gpt4 book ai didi

javascript - vuex 是 state.array.push 响应式(Reactive)的吗?

转载 作者:搜寻专家 更新时间:2023-10-30 22:53:03 25 4
gpt4 key购买 nike

我对 JS 和 vue 有点陌生,不太确定我是否正确理解了文档。它说:

Due to the limitations of modern JavaScript (and the abandonment of Object.observe), Vue cannot detect property addition or deletion. Since Vue performs the getter/setter conversion process during instance initialization, a property must be present in the data object in order for Vue to convert it and make it reactive.

这是否也包括普通数组,或者数组中的元素不算作 javascript 中的“属性”?我希望对数组执行 state.array.push(data) 。这是正确的做法吗?

最佳答案

关于 docs :

Due to limitations in JavaScript, Vue cannot detect the following changes to an array:

  1. 当您直接使用索引设置项目时,例如vm.items[indexOfItem] = newValue
  2. 当你修改数组的长度时,例如vm.items.length = newLength

Vue will keep reactivity (Array change detection) when using:

  1. 推送()
  2. 弹出()
  3. 移位()
  4. 取消移位()
  5. 拼接()
  6. 排序()
  7. 反转()

所以问题的答案是 state.array.push react 性的吗?

关于javascript - vuex 是 state.array.push 响应式(Reactive)的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56898871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com