javascript - Vuejs - 更新数组中的对象

标签 javascript vue.js

我正在使用 VueJs,并且有一个对象数组。我想要做的是根据索引更新数组中的对象。为此我写了一个方法:

updateRow(index) {
      this.inputs[index]={ "one": "test", "two": "test" }
    }

但是,该对象只是不更新​​。我为其创建了以下 jsbin。

https://jsbin.com/boturuluxe/1/edit?html,js,console,output

感谢任何帮助。

最佳答案

由于 JavaScript 的限制,Vue 无法检测到数组的以下更改:

  1. 当你直接用索引设置一个项目时,例如vm.items[indexOfItem] = newValue

  2. 当你修改数组的长度时,例如vm.items.length = newLength

解决办法是: this.$set(this.inputs, index, { "one": "test", "two": "test"})

Read more here

关于javascript - Vuejs - 更新数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55512908/

相关文章:

javascript - 仅当屏幕超过 760px 时才调整表格大小

javascript - 类型错误 : TypeError: undefined is not an object (evaluating '_this.state.scheduleList' )

javascript - 在 Vuejs 中调用数据内部的方法

php - 如何允许其他网络连接到服务器Node.js套接字IO

javascript - 在 Node 中的进程之间发送数据是否昂贵/高效?

javascript - 单击 div 后通过 jquery 更改 css

javascript - 使用 Vuex 将数据绑定(bind)到组件

javascript - 将 Base64/BLOB 图像数据从 PHP 发送到 Javascript

javascript - Vue为每个项目向下滑动过渡

javascript - 如何在 Vue.js 中传递动态页面 :id to $http. 获取 url