Vue  $EventBus

2022-06-26  本文已影响0人  啵崽崽

main.js

Vue.prototype.$EventBus = new Vue()

this.$EventBus.$emit(“shijianmingcheng “,{a:1}

第一个参数:事件名称

第二个参数:需要传递的数据

this.$EventBus.$on(“shijianmingcheng “, record=>{ this.b=record.a}

第一个参数: 对应的事件名称

第二个参数:接收对应事件的参数

this.$EventBus.$off(“shijianmingcheng)

移除事件

上一篇 下一篇

猜你喜欢

热点阅读