-
Notifications
You must be signed in to change notification settings - Fork 384
react 禁止“事件冒泡” #9
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
Comments
omg |
@simongfxu 是如何处理的呐? |
@Thinking80s 文章已过时,React现在已经没有这个问题了。 |
大概是什么原理呢? |
我用的event.stopPropagation()是可以阻止事件冒泡的 |
给 Icon 加个样式 pointer-events: none 就能直接解决 |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
标题的说法其实不太准确,因为react原生的事件系统本身就是事件代理的,意味着事件会一直冒泡到document进行绑定。所以,使用普通的**event.stopPropagation();**是没有办法在react中实现阻止事件“冒泡”类似的操作的。
stackoverflow和github issue上都有相关的讨论,比如
最后我找到了一个比较简单地解决方法,就是 react-native-listener。
参考地址:https://www.npmjs.com/package/react-native-listener
The text was updated successfully, but these errors were encountered: