Vue2中EventBus总线使用

参考 https://juejin.cn/post/6995015040805896200

在utils文件夹中创建bus.js文件

import Vue from 'vue';
export const Bus = new Vue();

在需要的地方使用

// Fisrt
import { Bus } from '../../utils/Bus.js';
  // 监听数据
  mounted() {
    Bus.$on('toggleData', (data) => {
      this.toggle = data;
    });
  },
  // 清空Bus
  beforeDestroy() {
    Bus.$off();
  }

// Second
import {Bus} from "../../utils/Bus.js"

    goPmPage() {
      Bus.$emit("toggleData", true);
      this.$router.push("/manage/govproject");
    },

  beforeDestroy() {
    Bus.$off()
  }

posted @ 2023-03-02 17:11  Felix_Openmind  阅读(359)  评论(0)    收藏  举报
*{cursor: url(https://files-cdn.cnblogs.com/files/morango/fish-cursor.ico),auto;}