这里我想为sendqnt
和recieveqnt
设置默认值
export default{
data: function(){
return{
businessforCustomer:false,
transactionData:{
business:{},
senditems:{
sendqnt:0,
},
recieveitems:{
recieveqnt:0,
},
},
}
}
在循环中将那些数据设置为v-model
<tr v-for="ri in transactionData.recieveitems">
<td>{{ri.item_name}}</td>
<td>
<input type="text" class="form-control" placeholder="Item Quantity" v-if="" v-model.number="ri.recieveqnt" >
</td>
</tr>
和
<tr v-for="si in transactionData.senditems">
<td>{{si.item_name}}</td>
<td><input type="text" class="form-control" placeholder="Item Quantity" v-model.number="si.sendqnt">
</td>
</tr>
提前谢谢。
“设置transactionData.senditems”
axios.get('/api/transactions/getItems')
.then(function (response){
app.transactionData.senditems = response.data;
console.log(response);
})
.catch(function (response){
console.log(response);
})
答案 0 :(得分:0)
如果响应不是数组,则将其忽略。如果它是一个数组-如果缺少每个项目的属性receiveqnt
,则将其设置为0。
axios.get('/api/transactions/getItems')
.then(function (response){
if(Object.prototype.toString.call(response.data) === '[object Array]') app.transactionData.receiveitems = response.data.map((item) =>
{
item.recieveqnt = item.recieveqnt || 0;
return item;
});
else app.transactionData.receiveitems = [];
console.log(response, app.transactionData.receiveitems);
})
.catch(function (response){
console.log(response);
})