You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
616 B
25 lines
616 B
/* 事件绑定传递额外参数
|
|
如果传递自定义参数
|
|
1.只需要一个额外参数 {clickHandler} -> {()=>clickHandler('自定义的参数')}
|
|
2.既需要 e 也需要额外的参数 {(e)=>clickHandler(e, '自定义的参数')} */
|
|
|
|
function Hello() {
|
|
// 定义事件回调函数
|
|
const clickHandler = (e, message) => {
|
|
console.log('函数组件中的事件被触发了', e, message)
|
|
}
|
|
// 事件绑定
|
|
return (
|
|
<div onClick={(e) => clickHandler(e, '这是一条消息')}>hello everybody</div>
|
|
)
|
|
}
|
|
|
|
function App() {
|
|
return (
|
|
<div>
|
|
<Hello />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default App
|