【发布时间】:2020-01-13 09:28:22
【问题描述】:
我想在同一个输入中使用V-model 和Value。我想将Value 用作来自relationship Laravel 的Initial 值,并将V-model 用作输入。
谷歌搜索了几分钟后,我发现V-model 和Value 不能使用相同的输入。
但是有人告诉我,我可以在mounted 的某个地方指定一个初始值。我照他们说的做了。
created() {
for (let i in this.form.products) {
this.form.products[i].quantity = this.form.products[i].pivot.quantity;
console.log(this.form.products);
}
},
但还是没用。
在我的 Vuejs 中
<table>
<tr class="tablePurchase--td" v-for="(item, index) in form.products" :key="index">
<td>{{item.name}}</td>
<td>{{item.code}}</td>
<td>
<input
type="number"
class="table-quantity"
v-model="form.products[index].pivot.quantity"
/>
</td>
<td>
<input
type="number"
class="table-quantity"
v-model="form.products[index].pivot.unit_price"
placeholder="0.00"
/>
</td>
</tr>
</table>
有人可以帮忙吗?
【问题讨论】:
-
form属性是否注册在组件数据中?或者它只是一个动态属性? -
@Jerodev 是的,
form在数据中注册..