我有以下vue2代码Vue公司未反应数据变化
methods: {
open: function(conversation){
conversation.loading = true;
this.$set(this, 'activeConversation', conversation);
this.$http.get('/conversation/messages', {
params: {
conversationId: conversation.id
}
}).then((response) => {
// this.$set(this.activeConversation, 'messages', response.data); // this was the first try
this.activeConversation.messages.push(response.data[0]); // this is the second try
})
}
}
当我改变activeConversation模板反应,第一$集。但是当我更改activeConversation的消息属性时,什么都不会发生。 我看到vue devtools中的更改,但DOM中没有任何更改。
没有什么变化,我的意思是v-for =“在activeConversation.messages中的消息”不会呈现任何东西。在我有activeConversation:null的数据中也没有{{activeConversation}}
。作为谈话的我通过与ID,发送对象,消息
是否'activeConversation'属性在你的''数据属性messages'()'组件的方法?如果没有,请将其添加并重试。除此之外,您可以直接设置属性而不是调用'$ set'。 –
在你的'v-for'中有''key'这样的'v-for =“消息在activeConversation.messages”:key =“message”'? – SLYcee
no .. activeConversation = null默认 – John