I want to pre-select a particular value in a select drop-down generated by vue-multiselect
.
I can get this to work fine if I have a simple array of strings like the following:
['Test 1', 'Test 2', 'Test 3']
However, when I use an array of objects, I can't get this to work. For example, if I have the following:
<v-multiselect :options="[{id: 1, name: 'Test 1'}, {id: 2, name: 'Test 2'}, {id: 3, name: 'Test 3'}]"
label="name"
track-by="id"
v-model="test">
</v-multiselect>
No matter what I set the test
data property that v-model is connected to, it won't preselect the value. I've tried 1
, 2
, 3
, '1'
, '2'
and '3'
for test
when track-by
is id
and 'Test 1'
, etc. when track-by
is name
but nothing seems to work.
What am I doing wrong here? I looked at the docs at https://vue-multiselect.js.org/#sub-single-select-object, but they don't seem to provide an example when you want to preset a value for an array of objects for the options. Googling has also not returned what I'm looking for.
On a related topic, once I get this working, what would I have to change to select multiple values for when I set the component to multiple
? Thank you.
vue-multiselect
should automatically handle this for you when you specifytrack-id
. – Harber