I am trying to display the select drop down using vs-select, the options are taken from the API. Here is my scenario I have made all my components dynamic, i have 3 cards in my front page, if I click any of the card respective contents are displayed.
Here is the response that I get from the /my-project
endpoint:
[
{
"uid": 1,
"choice": "project_title1|project_title2|project_title3",
"age": "35",
"country": "india"
},
{
"uid": 2,
"choice": "project_title2",
"age": "25",
"country": "australia"
}
...
]
Here is my code:
<span v-if="out.choice">
<template v-for="(val, e) in Myfilter(out.choice)">
<vs-select v-model="check" :key="e" :options="[{label: val}]" />
</template>
</span>
<div v-if="out.choice === 'project_title1'">
--show contents1--
</div>
<div v-if="out.choice === 'project_title2'">
--show contents2--
</div>
check: null,
out: null
// ...
methods: {
Myfilter (val){
return val.replaceAll('_', ' ').split('|')
},
SelectVue (id) {
this.$http.get(`/my-project/${id}`)
.then((res) => {this.out= res.data})
}
},
mounted (){
this.SelectVue (this.$route.params.uid)
}
If the user clicks on 2nd card he will get the details of uid=2
i.e in vue-select he will get the option as project title2
.
If the user clicks on 1st card he will get the details of uid=1 then three vue-select are displayed as shown in image:
Rather i want a single vue-select and three different options in it as:
Here is my question: How do i have a single vue-select for the data coming from API and then display different options for it.