正確寫法
this.formData =
{
channelId: 0,
apple:0,
bizTypeId: 0,
createTime: '',
};
if(!this.isManager){
this.formData.apple=this.apple;
}
將完整的對象賦值給目標變量,而后再依據條件修改屬性值
先定義對象,后給對象添加屬性會導致對象的屬性讀取不到,這是vue天生的bug
如下是錯誤的寫法
this.formData =
{
channelId: 0,
bizTypeId: 0,
createTime: '',
};
if(!this.isManager){
this.formData.apple=this.apple;
}else{
this.formData.apple=0;
}
//頁面上綁定apple的元素可能讀取不到變量的值