我有一个使用 vue.js 的应用程序。我在对象数组中使用 v-for 生成结果列表。 当我使用下划线 _.extend 更新数组中第 n 个项目内的对象时,项目 View 不会更新。 http://vuejs.org/guide/reactivity.html 上有针对此问题的解决方案这表示像这样使用 _.extend:
this.results.displayed[key] = _.extend({}, this.results.displayed[key], detail.items);
但问题是当我像它说的那样使用扩展时,它不会更新 View 。
最佳答案
当您通过数组索引设置新项目时,Vue 无法检测到更改。要解决这个问题,您可以使用 Vue 添加到数组的 $set()
方法。
var newObject = _.extend({}, this.results.displayed[key], detail.items);
this.results.displayed.$set(key, newObject);
更多信息 here .
关于javascript - 更新 v-for 中使用的数组内的对象时,Vue js react 性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35254057/