需要一个bus.js文件代码如下
import Vue from 'vue';
export default new Vue();
在父组件中引入
import bus from '@/api/bus.js'
在created中使用:
created() {
bus.$on('addCondition', (type) => {
this.checkBefor = type
})
}
子组件中使用
import bus from '@/api/bus.js' //引入
bus.$emit('addCondition', true); //子组件的事件中使用