1. Establish a transfer station
Create a util.js transfer station file (anywhere, I am in /assets/js/util.js)
import Vue from 'vue'
export default new Vue
2. Introduce the file on two pages respectively (note the path)
例如:import events from '@/assets/js/util.js'
3. Caller code
methods: {
functionA() {
Utils.$emit('demo','msg');
}
}
Fourth, the callee code
mounted(){
var that = this;
Utils.$on('demo', function (msg) {
console.log(msg);
that.functionB();
})
},
methods: {
functionB() {
...
}
}