0

Is there a way to use a v-select to display the values of an array? I need to list the str values of this array:

myArr: [
            { key: 'one', str: '1st' },
            { key: 'two', str: '2nd' },
            { key: 'three', str: '3rd' },
            { key: 'four', str: '4th' }
]

in the v-select but can't figure out how to do it. So far I've got this working:

<v-select v-model="vCase.eligibility" :items="eligPeriods[0].str"></v-select>

It displays "1st" in the v-select. But I need all the values to display.

I tried using a template:

<template v-slot:myArr="{item}">
        <v-select v-model="myVar.selectedVal" :items="item[str]"></v-select>
</template>

but then it doesn't even render on the page.

Any help or advice?

half of a glazier
  • 1,864
  • 2
  • 15
  • 45

1 Answers1

0

Since you have an associative array as items you will need to do something like this

<v-select :options="myArr" :reduce="item => item.key" label="item.str" />

You can read more about it here