Vue JS如何删除僵尸事件?

时间:2017-01-18 17:49:54

标签: javascript vue.js vuejs2

如何删除僵尸事件?

当向前和向后切换$ on事件时,可以多次使用。

App.vue

<script>
  export default {
    methods: {
      go: function () {
        console.log('event received')
      }
    },
    created: function (){
        this.$parent.$on('go', this.go);
    }
  }
<script>

Children.vue

{{1}}

2 个答案:

答案 0 :(得分:0)

created生命周期挂钩中有click方法,因此只要呈现children组件,就会调用它。

答案 1 :(得分:0)

删除组件时需要删除事件:

<script>
  export default {
    methods: {
      go: function () {
        console.log('event received')
      }
    },
    created: function (){
        this.$parent.$on('go', this.go);
    },
    beforeDestroy: function (){
        this.$parent.$off('go',this.go);
    }
  }
<script>
相关问题