vue跨组件通信
提示事件 (vue-tabevents)
Easy communication between tabs for Vue 2.x.
Vue 2.x的选项卡之间易于通信。
入门 (Getting Started)
正在安装 (Installing)
Install with npm:
使用npm安装:
npm install --save vue-tabevents
import into project:
导入项目:
import Vue from 'vue';
import vueTabevents from 'vue-tabevents';
Vue.use(vueTabevents);
用法 (Usage)
To an emit event to other tabs
向其他选项卡发出事件
this.$tabEvent.emit('eventName');
const data = {
name: 'Ali'
phone: 123
}
this.$tabEvent.emit('eventName', data);
To listen for events emitted by other types
侦听其他类型发出的事件
this.$tabEvent.on('eventName', callback);
this.$tabEvent.on('eventName', (data) => console.log(data));
To stop listening to an event
停止收听事件
this.$tabEvent.off('eventName');
翻译自: https://vuejsexamples.com/event-based-communication-across-opened-tabs-for-vue/
vue跨组件通信