因为Vue是响应式的,所以当数据发生变化时,Vue会自动检测数据变化,视图会发生相应的更新。
1、push()
在数组最后添加元素,可以添加多个元素
this.test.push('abc')
this.test.push('abc','def')
2、pop()
删除数组中最后一个元素
this.test.pop()
3、shift()
删除数组中的第一个元素
this.test.shift()
4、unshift()
在数组前面添加元素,可以添加多个元素
this.test.unshift('abc')
this.test.unshift('abc','def')
5、splice()
可以删除、插入、替换数组中的元素
1、删除下标为1的元素开始的两个元素
this.test.splice(1,2)
2、替换下标为1的元素开始的两个元素
this.test.splice(1,2,'a','b')
3、从下标为1的位置插入元素
this.test.splice(1,0,'a')
6、sort()
使数组降序排序
this.test.sort()
7、reverse()
反转数组顺序
this.test.reverse()