如何在反应链接组件上使用 onClick 事件? [英] How to use onClick event on react Link component?
本文介绍了如何在反应链接组件上使用 onClick 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 reactjs 路由器中的 Link 组件,但无法使 onClickevent 正常工作.这是代码:
I am using the Link component from the reactjs router and I cannot get the onClickevent working. This is the code:
<Link to={this.props.myroute} onClick='hello()'>Here</Link>
这是这样做的方式还是其他方式?
Is this the way to do it or another way?
推荐答案
您将 hello()
作为字符串传递,同时 hello()
表示执行 你好
马上.
You are passing hello()
as a string, also hello()
means execute hello
immediately.
试试
onClick={hello}
这篇关于如何在反应链接组件上使用 onClick 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文