vue Bus事件用法与bug
    var vm = new Vue({
    el: '#app',
    data: {
        // 空的实例放到根组件下,所有的子组件都能调用
        Bus: new Vue()
    },
    template: '<App/>',
    components: { App },
  })
this.$root.Bus.$emit("exportschre",this.count); //发送事件
this.$root.Bus.$on('exportschre', value => {})//事件监听
在监听的时候发现会触发多次,解决办法就是在组件销毁的时候也销毁该事件,但是在router-link路由切换之后就会无法监听,所以有些情况存在bug,具体情况具体分析
beforeDestroy() { this.$root.Bus.$off("exportschre"); }
router-link路由切换之后就会无法监听解决办法:就是在监听之前先销毁改事件,然后就只触发一次
this.$root.Bus.$off("exportschre"); this.$root.Bus.$on('exportschre', value => { })
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号