Answer the question
In order to leave comments, you need to log in
How can I create my own unique v-model for each v-select on the page?
I display such multiselect menus on my page
<template v-slot:item.people="{ item }">
<v-select
@input="onInput"
:items="people"
v-model="selected"
item-text="name"
item-value="surname"
label="Select"
return-object
multiple
></v-select>
</template>
data: {
// Модель доступных для выбора элементов.
people: [{
name: "Adam",
surname: "Brown",
}, {
name: "Bruce",
surname: "Lee",
}, {
name: "Erl",
surname: "Black",
}],
// Модель выбранных элементов.
selected: [],
},
Answer the question
In order to leave comments, you need to log in
data: () => ({
people: [{
name: "Adam",
surname: "Brown",
}, {
name: "Bruce",
surname: "Lee",
}, {
name: "Erl",
surname: "Black",
}],
selected: {}
}),
created () {
this.setModel()
},
methods: {
setModel () {
this.people.forEach((user, index) => {
this.$set(this.selected, `user${index}`, '')
})
}
}
selected: {
user1: '',
user2: '',
user3: '',
//...
}
v-model="selected[`user${index}`]" // если в цикле выводить селекты
v-model="selected.user1" // если просто ручками
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question