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