vue 中的组件通信

367 阅读1分钟

1、在main.js中引用传值中转站


Vue.prototype.$bus = new Vue();

2、 组件发送点击事件

showBtn() {
      this.$bus.$emit("dataChild");
    },

3、组件接受事件

created() {
    this.$bus.$on("dataChild", () => {
      this.formShow = !this.formShow;
    });
}