自定义vue事件无效

时间:2017-09-11 10:00:52

标签: javascript events vue.js

我试图在一个组件中捕获vue.js自定义事件,但它没有捕获。有什么问题?

myEventFunc: function() {
  this.myEvent = true;
},
clickedFunc: function() {
  this.clicked = true;
  this.$emit('myevent');
}

JSFiddle示例:https://jsfiddle.net/ucean0rh/1/

1 个答案:

答案 0 :(得分:0)

我不确定这是否是Vue处理它的方式,但它在我的JSFiddle中有效。只需在myEventFunc()内致电clickedFunc

new Vue({
  el: "#app",
  data: {
    myEvent: false,
    clicked: false,
  },
  methods: {
    myEventFunc: function() {
      this.myEvent = true;
    },
    clickedFunc: function() {
      this.clicked = true;
      this.myEventFunc();
      this.$emit('myevent');
    }
  }
})