Vue $set 动态响应数据

2020-01-14  本文已影响0人  ShindouHiro
<template>
    <div class="hello">
        {{ obj }}
    </div>
</template>

<script>
export default {
    mounted() {
        for (let i = 0; i < 3; i++) {
            this.obj[i] = [1, 2, 3];
        }
    },

    data() {
        return {
            obj: {}
        };
    }
};
</script>
<template>
    <div class="hello">
        {{ obj }}
    </div>
</template>

<script>
export default {
    mounted() {
        for (let i = 0; i < 3; i++) {
            this.obj[i] = [1, 2, 3];
        }
        this.$set(this.obj, this.obj);
    },

    data() {
        return {
            obj: {}
        };
    }
};
</script>
上一篇下一篇

猜你喜欢

热点阅读