vue.js 更新整个数组的最佳方式 [英] vue.js best way to update entire array
问题描述
更新整个观察到的数组并在 vue.js 中触发重新渲染而不必迭代推送所有项目的最佳方法是什么?
What is the best way to update the entire observed array and trigger a rerender in vue.js without having to iterate an push all the items?
我已阅读此处的文档:https://vuejs.org/v2/guide/list.html#Replace-an-Array
但是对于我来说,仅仅为了更新数组而必须过滤、连接或切片是没有意义的?一定是我遗漏了什么?
But it doesn't make sense to me having to filter, concat or slice just to update the array? There must be something I missed?
推荐答案
按照建议,我会自己回答这个问题,以帮助处于同样困境的任何人.
As suggested I will repond to this myself to help anyone in the same predicament.
oldArr = newArr
应该仍然有效(谢谢 choasia.尽管 vue.js 文档中有些不清楚.替换整个数组不会属于那里提到的警告(谢谢Roy J ).
should still work (thank you choasia. Even though it is somewhat unclear in the vue.js documentation. Replacing the entire array will not fall under the caveats mentioned there (thank you Roy J ).
一种选择也可能是清空数组然后推送新数组,例如:
One option might also be to to empty the array and then push the new one like:
yourArray.push(... yourNewArray)
谢谢reiner
这篇关于vue.js 更新整个数组的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!