Javascript 如何使用Vue.js从$emit payload中获取值
我正在从我的ConversationList(子组件)向ConversationModel(父组件)发出一个具有各种值的事件 对话列表Javascript 如何使用Vue.js从$emit payload中获取值,javascript,vue.js,vuejs2,vue-component,Javascript,Vue.js,Vuejs2,Vue Component,我正在从我的ConversationList(子组件)向ConversationModel(父组件)发出一个具有各种值的事件 对话列表 getConversation(conversation_id, receiver_id, username, avatar){ this.$emit('open-conversation', receiver_id, conversation_id, username, avatar); } 对话模式 Vue开发工具输出 模板 错误 “打开对话”的事件处
getConversation(conversation_id, receiver_id, username, avatar){
this.$emit('open-conversation', receiver_id, conversation_id, username, avatar);
}
对话模式
Vue开发工具输出
模板
错误
“打开对话”的事件处理程序中出错:“TypeError:无法读取未定义的属性“2”
我不明白。事件正在触发,并且在
devtools
中有一个我无法访问的有效负载对象。我做错了什么?在从子组件发射到父组件的事件中,您将收到与发射参数相同的参数:
因此,从getConversation
处理程序中删除$event
:
<converstations-list v-if="showConversation == false" v-on:open-conversation="getConversation"></converstations-list>
谢谢,效果很好。我不明白为什么它会这样工作。
<converstations-list v-if="showConversation == false" v-on:open-conversation="getConversation($event)"></converstations-list>
getConversation(event){
console.log(event.payload[0] + event.payload[1] + event.payload[2] + event.payload[2])
},
<converstations-list v-if="showConversation == false" v-on:open-conversation="getConversation"></converstations-list>
getConversation(receiver_id, conversation_id, username, avatar){
// do whatever you want with that parameters
}