Vue中使用数组

1、数组变化-视图更新-原始数组变化
  • push()
  • pop()
  • shift()
  • unshift()
  • splice()
  • sort()
  • reverse()
2、数组变化-视图更新-原始数组不变
  • filter()
  • concat()
  • slice()

3、数组变化-视图不变

  • 通过索引直接设置项
 this.items[2] = {name: 'abc'}

解决方式1:使用$set

this.$set(app.items, 2, {name: 'abc'})

解决方式2:使用splice()

this.items[2].splice(2, 1, {name: 'abc'})
  • 修改数组长度
this.items.length = 2

解决方法:

this.items.splice(2)

猜你喜欢

转载自blog.csdn.net/fengjingyu168/article/details/79782957