我正在使用 VueJs,并且有一个对象数组。我想要做的是根据索引更新数组中的对象。为此我写了一个方法:
updateRow(index) {
this.inputs[index]={ "one": "test", "two": "test" }
}
但是,该对象只是不更新。我为其创建了以下 jsbin。
https://jsbin.com/boturuluxe/1/edit?html,js,console,output
感谢任何帮助。
最佳答案
由于 JavaScript 的限制,Vue 无法检测到数组的以下更改:
当你直接用索引设置一个项目时,例如vm.items[indexOfItem] = newValue
当你修改数组的长度时,例如vm.items.length = newLength
解决办法是:
this.$set(this.inputs, index, { "one": "test", "two": "test"})
关于javascript - Vuejs - 更新数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55512908/