我在 vue 多选中使用 v-model 时遇到问题。多选需要将对象传递到 v-model 以获得初始选定值,以便它可以将该对象与选项对象匹配。 这是我的代码示例:
<b-tr v-for="(income, index) in this.incomes" :key="income.id">
<b-td>
<multiselect
:options="selectAccount"
v-model="{id:income.account_id,account:income.accounts.account}"
label="account"
track-by="id"
></multiselect>
</b-td>
</b-tr>
Vue 不接受以这种方式将对象传递到 v-model 中,而且我想不出另一种方法来做到这一点。
这是收入对象:
incomes: Array
0: Object
account_id:
accounts: Object
account:
id:
amount:
id:
date:
选项:
options: Array[3]
0: Object
account:
id:
最佳答案
您可以使 v-model 与一个数组相关,您可以通过主数组的索引传递每个元素,例如:
v-model="selected_options[index]"
并将 selected_value 设置为数组:
selected_options: []
关于javascript - 使用 VuejS 在 v-model 中传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59491223/