vue $set entire array - Stack Overflow
为情所困
为情所困 2017-06-26 10:56:27
0
3
960

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] } }
为情所困
为情所困

reply all (3)
某草草

Direct assignment
this.arr = ['h', 'e', '...'];

    学霸
    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') } }
      曾经蜡笔没有小新

      $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.

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!