使用this.$set呢 或者this.$nexttick
你可以在computed属性中计算出新的outOrderDetailList,并在模板中渲染它。这样可以确保新的statsQuantity在渲染表格时已经被赋值并且可以显示出来。
例如:
computed: {
updatedOrderDetailList () {
return this.outOrderDetailList.map(item => {
const statsQuantity = this.getStatsQuantity(item.matCode)
return {
...item,
statsQuantity
}
})
}
},
methods: {
getStatsQuantity (matCode) {
// 根据matCode获取statsQuantity
// ...
}
}
然后在模板中使用updatedOrderDetailList来渲染表格:
<table>
<thead>
<tr>
<th>物料编码</th>
<th>数量</th>
<th>现有库存</th>
</tr>
</thead>
<tbody>
<tr v-for="item in updatedOrderDetailList" :key="item.matCode">
<td>{{ item.matCode }}</td>
<td>{{ item.quantity }}</td>
<td>{{ item.statsQuantity }}</td>
</tr>
</tbody>
</table>