秘银上的事件捕获?

jan*_*t08 3 javascript mithril.js

is there no event capturing? Id like to force event handling order, in autocomplete component, onblur event fires before onclick on item in a list, causing the list to toggle twice and so remaining visible after flickering.

Bar*_*ney 6

Mithril 中的事件绑定是一个非常简单的便利功能,它代表使用标准的非捕获来绑定事件addEventListener,并自动对分辨率的重绘进行排队(这与 React 等其他视图库形成鲜明对比,在 React 中,事件绑定是一个精心设计的、固执己见的过程)自己的系统)。

当您想要以不同的方式做事时,Mithril 允许您内联访问生命周期方法,从而使直接 DOM 访问变得非常容易。具体来说,oncreate方法将允许您根据您的选择绑定事件

m('div', {
  // this
  onclick : e => {},
  // is the same as this
  oncreate: vnode => {
    vnode.dom.addEventListener('click', e => {
      m.redraw()
    })
  },
})
Run Code Online (Sandbox Code Playgroud)

请注意,click事件将始终在 后解决blur,即使前者正在捕获而后者正在冒泡 - 您可能需要mousedown改为使用。这是一个演示,展示了如何绑定捕获事件并记录不同事件的序列