全局data中的值传递(main.js文件)
// main.js文件定义eventHub值
data: {
eventHub: new Vue(),
},
// 设置传入全局eventHub中的值,getCardAccount为自定义函数 getCardAccount中的值为 111
this.$root.eventHub.$emit(
"getCardAccount",
111
);
// 设置模块下getCardAccount方法为传入getCardAccount函数
this.$root.eventHub.$on("getCardAccount", this.getCardAccount);
// 获取main.js全局值,通过getCardAccount函数获取设置的值
getCardAccount(val) {
// val = 111
this.roomCard = val;
},
复制代码