首页 > 其他分享 >全局时间总线,兄弟间传递信息

全局时间总线,兄弟间传递信息

时间:2022-08-28 18:01:10浏览次数:56  
标签:Vue bus clear 总线 传递信息 全局 store

在 入口文件 main中引入bus



new Vue({
  render: h => h(App),
  //注册路由
  router,
  //注册store
  store,
  //配置全局总线
  beforeCreate() {
    Vue.prototype.$bus = this
  },
}).$mount('#app')

在需要调用传递的函数中 声明要调用的 bus名称

methods:{
    removeKeyWord(){
      this.searchParams.keyword = undefined;
      this.goData();
      this.$bus.$emit("clear")
    }
}

在接受信息的地方配置调用函数

  mounted() {
    this.$bus.$on("clear",()=>{
        this.keyword=''
      }
    )
  },

标签:Vue,bus,clear,总线,传递信息,全局,store
From: https://www.cnblogs.com/xiaobo95/p/16633263.html

相关文章