- 對data對象或者數(shù)組值進(jìn)行操作,試圖數(shù)據(jù)并不會響應(yīng)
使用$set便可以讓數(shù)據(jù)響應(yīng),
<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>
- 此時對象的數(shù)據(jù)并不響應(yīng),使用$set
<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>
-
此時對象便可以動態(tài)響應(yīng)
image.png
