1.建立中间件:transfer-util.js
import Vue from 'vue'
export default new Vue();
2.home与alluserList文件为同级文件,home文件使用alluserList文件的方法,调用相当于home文件,被调用方为alluserList文件,具体写法如下:
两个页面分别引入中间件文件路径:
import transferUtil from '../../xb-share/util/transfer-util';
3.被调用方alluserList文件:
在mouted生命周期中调用:
mounted(){
var that = this
transferUtil.$on('demo', function() {
that.getOperation()//该文件有此方法;
})
},
4.调用方home文件:
transferUtil.$emit('demo', 'msg');