改变数组表示的状态的正确模式是什么?
在 Vuex 4 的标准示例中: VUEX4 GitHub 示例1
建议删除一个数组元素并插入一个新元素。
state.todos.splice(index, 1, {
...todo,
text,
done,
});
这是为 Vuex 4、Vue 3 更改存储数组的标准模式吗?
另一个直接修改数组中的对象字段的例子: VUEX4 GitHub example2
const cartItem = state.items.find(item => item.id === id)
cartItem.quantity++
在 Vuex 4 中改变状态数组而不失去反应性的正确方法是什么?是否可以通过索引直接修改数组的项目,例如 example2?VUEX4 是否具有反应性 - 或者反应性是唯一组件的属性?