我无法 $emit
从子组件到它的父组件的事件。我可以成功发送事件,但不能在父级中接收到它。
Results.vue
( 孩子):
<a href="#" v-on:click="sendResultValues"></a>
//
methods: {
sendResultValues: function () {
this.$emit('send-result-values', 'carrier');
}
},
当我点击 <a>
时,我可以通过 Vue DevTools 看到 $emit
事件被触发:
但是,console.log 中没有收到任何内容,因为我的代码如下(父):
Input.vue
( 父母):
<search-results></search-results> //Results.vue component
<search-popover v-on:send-result-values="showResultData"></search-popover>
//
methods: {
showResultData: function () {
console.log("Data received from child: ")
}
},
原文由 oliverbj 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要在
search-results
组件上监听事件,而不是在search-popover
上监听事件。Input.vue(父级):