- bus ->总线
- Vue.prototype.
$
bus = new Vue() main.js 设置 - this.
$
bus.$
emit(‘事件名称’, 参数) - this.
$
bus.$
on(‘事件名称’, 回调函数(参数)) - 如何将GoodsListItem.vue中的事件传入到Home.vue中?
非父子间的通信
- 使用事件总线
- 在GoodListItem.vue methods中发射事件
- this.
$
bus.$
emit(‘事件名称’, 参数)
- this.
- 在Home.vue ,mounted 周期函数中监听该事件
- this.
$
bus.$
on(‘事件名称’, 回调函数(参数))
- this.
$bus 事件总线-------处理非父子间的通信
最新推荐文章于 2024-05-23 16:46:28 发布