javascript - Mithril 上的事件捕获?

标签 javascript mithril.js

没有事件捕获吗? 我想强制事件处理顺序,在自动完成组件中, onblur 事件在 onclick 列表中的项目之前触发,导致列表切换两次,因此在闪烁后保持可见。

最佳答案

Mithril 中的事件绑定(bind)是一个非常简单的便利功能,它代表使用标准非捕获 addEventListener 绑定(bind)事件,并自动对分辨率重绘进行排队(这与其他 View 库不同)就像 React 一样,其中事件绑定(bind)本身就是一个精心设计的、固执己见的系统)。

当您想要以不同的方式做事时,Mithril 允许您内联访问生命周期方法,从而使直接 DOM 访问变得非常容易。具体来说,the oncreate method will let you bind events however you choose .

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

请注意,click 事件始终会在 blur 之后解析,即使前者正在捕获而后者正在冒泡 - 您可能需要使用 mousedown 相反。 Here's a demo showing how to bind capturing events and logging the sequence of different events .

关于javascript - Mithril 上的事件捕获?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58475642/

相关文章:

javascript - 来自 Mithril promise 链内的 ReferenceError 被默默地忽略

javascript - 如何在 mithril.js 中使用输入标签的 'value'

javascript - 使 Mithril 应用程序 SEO 友好

url-routing - 如何使用子组件(子组件)执行 Mithril 路由

javascript - <ul> 不是折叠的,只是扩展的

javascript - IndexOf 和多数组

javascript - 如何利用Sencha Touch框架中的 "pinch"触摸效果?

javascript - 在链接后插入图片

javascript - Javascript 中是否有像 VB 中那样的 With 语句

javascript - 迭代 Mithril 中的字符串列表并创建下拉列表