1.首先同一个vue实例来调用两个方法。所以可以建立一个中转站。
建立 util.js 中转站文件(任意位置,我是在 src/shift/util.js)
import Vue from 'vue'
export default new Vue
2.分别在两个页面引入该文件(注意路径)
import Utils from '@/shift/util.js';
3.调用方代码
methods: {
oneFunction() {
Utils.$emit('demo','msg');
}
}
4.被调用方代码
mounted(){
let that = this;
Utils.$on('demo', function (msg) {
console.log(msg);
that.twoFunction(); //这里就是调用你的方法
})
},
methods: {
twoFunction() {
...
}
}