【发布时间】:2019-10-18 15:25:33
【问题描述】:
我正在尝试更改计算属性中数据的值,但如果我使用 map 更改它,数据属性中的原始值也会更改。
我阅读了有关计算属性的文档,它不会改变原始值。
我阅读了有关地图的文档,它返回了一个带有更改的新对象。
new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript", done: false },
{ text: "Learn Vue", done: false },
{ text: "Play around in JSFiddle", done: true },
{ text: "Build something awesome", done: true }
]
},
computed: {
todos_computed() {
return this.todos.map((todo) => {
todo.text += ' - Changed'
return todo
})
},
},
})
jsfiddle:https://jsfiddle.net/hkqm6f30/1
【问题讨论】:
-
你正在修改原始文本对象,查看here了解更多信息
标签: vue.js