当我按下按钮messageIncompleted
时,它起作用了,但是当我单击messageCompleted
按钮时,数据消失了。您能帮我解决这个问题吗?
messageIncompleted() {
this.messages = this.messages.filter(messages => ! messages.completed );
this.disabledIncomplete = true;
},
messageCompleted() {
this.messages = this.messages.filter(messages => messages.completed );
this.disabledComplete = true;
}
答案 0 :(得分:0)
当您单击messageIncompleted
时,this.messages
数组将更新为包含messages.completed = false
的项目。当您单击messageCompleted
时,messages
数组将没有任何带有messages.completed = true
的项目。
要解决此问题,您可以创建另一个名为filteredMessages
的属性,用于根据条件存储和显示消息。默认情况下,您可以将其设置为this.messages
。这样,messages
数组将不会直接突变。
messageIncompleted() {
this.filteredMessages = this.messages.filter(messages => !messages.completed);
this.disabledIncomplete = true;
},
messageCompleted() {
this.filteredMessages = this.messages.filter(messages => messages.completed);
this.disabledComplete = true;
}