vue.js - Vue:使用按钮单击时,发射器在子级中不起作用
问题描述
单击按钮时未调用我的发出调用。我试图运行一个调试器并单步执行它并触发它,但看起来它直接执行并跳过它。我不确定问题是什么或为什么会跳过。
家长
<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);
}
解决方案
您不能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
推荐阅读
- javascript - 为什么使用不同的计算机时“WebRTC 屏幕共享”没有流式传输?
- javascript - 如何为通过 document.createAttribute("id") 创建的 id 赋值
- javascript - 为什么我的点击事件是最后一个事件?
- keras - Keras 层和自定义函数的输入是什么?
- azure-web-app-service - IDX21323 错误,有时在 azure b2c 中的 URL 中循环
- macos - Safari 是否仅将完整加载的页面放入历史记录中?
- c# - 尝试使用 JSON.NET 使用周围的 [] 字符反序列化 JSON
- excel - Export-Csv .csv 文件格式不正确
- user-interface - 托管在 IIS8 上时,Silverlight 无法正确呈现
- r - 如何检查一个数字序列是否是斐波那契序列并获得 R 中的下一个值?