How to use $set to change the entire array
data: {
arr: [1,2,3,4]
},
methods: {
fun: function(){
//改变一个元素
this.$set(this.arr, 2, 'a3')
//改变整个数组 应该怎么写
//this.arr = [9,8,7]
}
}
欧阳克2017-06-26 10:58:27
methods: {
fun() {
this.$set(this, arr, ['a', 'b', 'c'])
},
fun2() {
this.arr = ['a', 'b', 'c']
},
fun3() {
this.arr.splice(0, this.arr.length, 'a', 'b', 'c')
}
}
曾经蜡笔没有小新2017-06-26 10:58:27
$set is generally used to add key-value pairs to objects. Arrays can be directly assigned values. For data operations, js-related operations will be monitored.