@elisha_langworth
To display nested data in a v-select component from Vuex store, you need to follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
state: {
options: [
{
id: 1,
label: 'Option 1',
subOptions: [
{
id: 11,
label: 'Sub-option 1'
},
{
id: 12,
label: 'Sub-option 2'
}
]
},
{
id: 2,
label: 'Option 2',
subOptions: [
{
id: 21,
label: 'Sub-option 3'
},
{
id: 22,
label: 'Sub-option 4'
}
]
}
]
}
|
1 2 3 4 5 6 7 |
import { mapState } from 'vuex'
export default {
computed: {
...mapState(['options'])
}
}
|
1 2 3 4 5 6 7 8 9 |
<template>
<v-select
v-model="selectedOption"
:items="options"
item-text="label"
item-value="id"
return-object
></v-select>
</template>
|
In this example, the item-text prop is set to 'label' to display the 'label' property of each option, and the item-value prop is set to 'id' to bind the 'id' property of each option.
That's it! Now, the v-select component will display the nested data from the Vuex store, and you can select an option or sub-option from the dropdown list.