react audio
和 video
标记上的每个事件都有一个重复项,例如它具有 onCanPlayThrough
属性和 onCanPlayThroughCapture
也是如此。它们在浏览器中的行为完全相同。
我们是否需要使用...Capture
事件而不是标准事件?他们的主要想法是什么?我在哪里可以找到有关它们的信息。
最佳答案
React 文档 here 对此进行了介绍。 ,尽管很容易错过:
The event handlers below are triggered by an event in the bubbling phase. To register an event handler for the capture phase, append
Capture
to the event name; for example, instead of usingonClick
, you would useonClickCapture
to handle the click event in the capture phase.
DOM 事件有 multiple phases (见下图),分别是(按顺序):
- 捕捉
- 目标
- 冒泡
通常我们使用目标或冒泡(addEventListener
的 false
第三个参数[默认]),但在极少数情况下您希望 Hook 到捕获阶段相反(第三个参数 = true
)。 ...Capture
处理程序可以让您做到这一点。
关于reactjs - 什么是 React ...Capture 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42439541/