Vue:使用按钮单击时,发射器在儿童中不起作用

时间:2020-05-27 01:29:28

标签: vue.js vuejs2

我的发射呼叫没有在我的按钮单击上被呼叫。我试图运行调试器并逐步执行它,但它被触发,但看起来像逐步执行并跳过它。我不确定问题是什么或为何跳过。

父母

<step-review @emitgetappdata="getAppData"></step-review> 
getAppData: function(data=null) {
  debugger
}

分步查看

<button @click="this.clickedButton()">Test</button>
clickedButton: function() {
  console.log("reached here");
  let data = {
    text: "Foo",
  }
  this.$emit('emitgetappdata', data);
}

1 个答案:

答案 0 :(得分:1)

您不能在视图上使用this

<button @click="clickedButton()">Test</button>
clickedButton() {
  console.log("reached here");
  let data = {
    text: "Foo",
  }
  this.$emit('emitgetappdata', data);
}

和您的组件代码更加简洁。

<step-review @emitgetappdata="getAppData"></step-review> 

getAppData(data=null) {
  debugger
}

在阅读一些文档后进行了编辑: https://vuejs.org/v2/guide/instance.html#Data-and-Methods