vuejs/v2.cn.vuejs.org

Vue 不能检测以下数组的变动:通过索引或长度改变数组。有歧义

xjphhh opened this issue · 0 comments

经过我测试,经过我测试, Vue.js v2.6.12版本的对于文档上Vue 不能检测以下数组的变动:通过索引或长度改变数组。这一点有歧义。
我的测试js代码:

var app = new Vue({
    el: '#app',
    data() {
        return {
            items: [1, 2, 3]
        }
    },
    methods: {
        change() {
            console.log(22222222)
            this.items[1] = 4
        }
    }
})

当data里只有一个纯数组的时候确实不不能通过索引改变数组。
但是当我

var app = new Vue({
    el: '#app',
    data() {
        return {
            arr: [{ id: 1, name: 'aa' },{ id: 2, name: 'bb' }],
            arr2: [1, 2, 3]
        }
    },
    methods: {
        change() {
            this.arr[1].name = 'cc';
            this.arr2[1] = 4;
        }
    }
});

有两个数组的时候却可以通过索引改变数组!!!