
最近准备做路由导航前处理好数据,所以做了一个全局的进度组件,但是需要事件派发与接受。
官方给出的最简单的升级建议是使用集中的事件处理器,而且也明确说明了 一个空的vue实例就可以做到,因为Vue 实例实现了一个事件分发接口
在vue2.0中在初始化vue之前,给data添加一个 名字为eventhub 的空vue对象

父组件监听

子组件触发调用

其实,我觉得官方为什么不使用 this.$root.$on ,this.$root.$emit呢
最近准备做路由导航前处理好数据,所以做了一个全局的进度组件,但是需要事件派发与接受。
官方给出的最简单的升级建议是使用集中的事件处理器,而且也明确说明了 一个空的vue实例就可以做到,因为Vue 实例实现了一个事件分发接口
在vue2.0中在初始化vue之前,给data添加一个 名字为eventhub 的空vue对象
父组件监听
子组件触发调用
其实,我觉得官方为什么不使用 this.$root.$on ,this.$root.$emit呢
本文标题:vue2.0组件间事件派发与接收
本文链接:https://www.haomeiwen.com/subject/pxeuhqtx.html
网友评论