動態添加對象屬性html
//聲明
var travelMainVueObj;
travelMainVueObj = new Vue({
"el" : "#portletContent",
"data" : {
checkBudgetData: {}//預算檢查
}
});
//使用 js部分
var checkBudgetText = "";
var checkBudgetFlag = "1"; //1表明 預算執行控制檢查經過; 2表明違反柔性;
var checkBudgetObject = {};
if(noPassSize == 0 ){
//預算執行控制檢查經過
checkBudgetText = "預算執行控制檢查經過";
checkBudgetFlag = "1";
}else{
//有N條違反柔性,待查看
checkBudgetText = "有 "+ noPassSize +" 個違反柔性 待查看";
checkBudgetFlag = "2";
}
Vue.set(travelMainVueObj.checkBudgetData,"checkBudgetResult",checkBudgetText);
Vue.set(travelMainVueObj.checkBudgetData,"checkBudgetFlag",checkBudgetFlag);
//使用 html部分
<div class="rowContent">
<span class="pass" id="checkBudgetResultPass" v-if="checkBudgetData.checkBudgetFlag == '1'">
{{checkBudgetData.checkBudgetResult}}
</span>
<span class="reject" id="checkBudgetResultReject" v-else-if="checkBudgetData.checkBudgetFlag == '2'">
{{checkBudgetData.checkBudgetResult}}
</span>
</div>
語法:
Vue.set(更新vue的對象或者數組,"key的名字",key的值);
Vue.set()在methods中也能夠寫成this.$set()