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.

28 lines
463 B

2 years ago
  1. // 函数组件的创建和渲染
  2. // 创建
  3. function Hello() {
  4. // 定义事件回调函数
  5. const clickHandle = (e) => {
  6. // 阻止默认行为
  7. e.preventDefault()
  8. alert('函数组件中的事件被触发了')
  9. }
  10. // 事件绑定
  11. return (
  12. <div>
  13. <a onClick={clickHandle} href="https://123.sogou.com/">
  14. 搜狗
  15. </a>
  16. </div>
  17. )
  18. }
  19. function App() {
  20. return (
  21. <div>
  22. <Hello />
  23. </div>
  24. )
  25. }
  26. export default App