我已经得到了我想要绑定到空数组的基本选择。我使用vuetify,但这个问题很普遍。
<v-select
v-model="items.physicianSpeciality"
>
</v-select>
现在我想使用相同的select到多个数组,取决于offer.person值,可以是医生,护士等。
data: {
offer.person: "physician" //or offer.person: "nurse"
}
例如对于医生我想要使用v-model items.physicianSpeciality
对于护士我想使用v-model items.nurseSpeciality
等。
我尝试做类似的事情:
<v-select
v-model="this['items.' + offer.person + 'Speciality']"
>
</v-select>
但这给了我一个错误:
[Vue warn]: Property or method "items.physicianSpeciality"
is not defined on the instance but referenced during render.
Make sure that this property is reactive, either in the data option,
or for class-based components, by initializing the property.
虽然这有效:
<v-select
v-model="items.physicianSpeciality"
>
</v-select>
这里有什么问题?如何更正我的代码才能使其工作?
答案 0 :(得分:1)
更改
v-model="this['items.' + offer.person + 'Speciality']"
到
v-model="items[offer.person + 'Speciality']"