关于vue里,同级页面A-B下,A调用B中refresh()的方法:
创建一个公共js文件,例命名为callUtils.js
callUtils.js
import Vue from 'vue'
export default new Vue
页面A:引入方法页面(参数data)
// 触发事件handleChange
handleChange() {
callUtils.$emit('yourName') //不带参数
callUtils.$emit('yourName','data') //带参数
}
页面B:被引方法页面(参数data)
mounted() {
// 不带参数
callUtils.$on('yourName', () => {
this.refresh()
})
// 带参数
callUtils.$on('yourName', (data) => {
this.refresh()
})
},
methods: {
// 调用方法function
refresh() {}
}