十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
數(shù)據(jù)丟失是框架的BUG,vue中的數(shù)據(jù)綁定是通過ES5中屬性的特性實現(xiàn)的。所以沒有設(shè)置特性的數(shù)據(jù),就會丟失。以下mounted中的四種操作都會導(dǎo)致數(shù)據(jù)丟失。
<
template>
<
div>
<
div>{{ colors }}
div>
<
div>{{ obj }}
div>
<
div>{{ intro }}
div>
div>
template>
<
script>
export
default {
data() {
return {
colors: [
"red",
"green",
"blue"],
obj: {},
};
},
mounted() {
// 1 數(shù)組中的值類型修改
this.colors[1] = "pink";
// 2 數(shù)組中的新成員
this.colors[3] = "gold";
// 3 對象中的新屬性
this.obj.size = 200;
// 4 未初始化的數(shù)據(jù)
this.intro = "111111";
},
};
script>