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

2 years ago
  1. /*
  2. 如果传递自定义参数
  3. 1.只需要一个额外参数 {clickHandler} -> {()=>clickHandler('自定义的参数')}
  4. 2.既需要 e 也需要额外的参数 {(e)=>clickHandler(e, '自定义的参数')} */
  5. function Hello() {
  6. // 定义事件回调函数
  7. const clickHandler = (e, message) => {
  8. console.log('函数组件中的事件被触发了', e, message)
  9. }
  10. // 事件绑定
  11. return (
  12. <div onClick={(e) => clickHandler(e, '这是一条消息')}>hello everybody</div>
  13. )
  14. }
  15. function App() {
  16. return (
  17. <div>
  18. <Hello />
  19. </div>
  20. )
  21. }
  22. export default App