如题:有组件A,组件B,
组件A用函数(方法)触发组件B中的函数(方法)
1.需要新建一个js文件:bus.js
2.两个组件都需要引用这个js文件:
closeoropenLeftnav() { if (this.IsShowLeft) { this.IsShowLeft = false; this.className = "GkCloseOrOpen"; } else { this.IsShowLeft = true; this.className = ""; } bus.$emit("IsCollapse", this.IsShowLeft); }
关键代码:
created() { bus.$on("IsCollapse", propMsg => { this.isCollapse = propMsg; }) },
原文:https://www.cnblogs.com/PiaoYu/p/11386373.html