简体   繁体   English

自定义Vue事件不起作用

[英]Custom vue events not working

I am trying to catch vue.js custom event within one component, but it's not catching. 我正在尝试在一个组件中捕获vue.js自定义事件,但没有捕获。 What's the problem? 有什么问题?

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

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

I'm not sure if this is a Vue way of dealing with it, but it works in my JSFiddle. 我不确定这是否是Vue的处理方式,但是它在我的JSFiddle中有效。 Simply call myEventFunc() from within clickedFunc : 只需在clickedFunc调用myEventFunc()

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');
    }
  }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM