Answer the question
In order to leave comments, you need to log in
Loading data in select vue js?
There is a select component
<template>
<div>
<div class="vue-dropdown" :class="{'vue-active':toggle}">
<span @click="toggle = !toggle">{{ value.length ? value : defaultValue }}</span>
<div class="vue-dropdown-collapsed" v-if="this.toggle">
<input type="text" v-model="search" v-if="showSearch === 'true'" :placeholder="inputPlaceholder" @click="toggle == true">
<ul>
<li v-for="(option, index) in options" :key="index" @click="toggle = false, value = option.name, selectedItem(option)" v-if="option.name.toLowerCase().indexOf(search.toLowerCase()) !== -1">{{ option.name }}</li>
</ul>
</div>
</div>
</div>
</template>
<template>
<div>
<div v-for="(field, index) in formFields" :key="index">
<dropdown :id="field.id" @open="fetchDropdownData(field.id)" v-else-if="field.type == 'select'" :options="dropdownsData[field.id]" default-value="Make a choice" show-search="false" input-placeholder="Выберите"></dropdown>
</div>
</div>
</template>
formFields: [
{
name: 'my_field',
class: 'moi_class',
type: 'input',
component: 'ui_input',
id: 1
},
{
name: 'brand',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 2
},
{
name: 'model',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 3
},
{
name: 'brand',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 4
},
{
name: 'model',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 5
},
{
name: 'brand',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 6
},
{
name: 'model',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 7
},
{
name: 'brand',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 8
},
{
name: 'model',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 9
}
]
fetchDropdownData(id) {
const currentDropdownData = axios.get('../../../static/json/v1/auto.json').then(response => {
this.dropdownsData.push(response.data);
}).catch(e => {
console.log(e)
})
console.log(this.dropdownsData)
}
this.dropdownsData
arrays of objects fall; :options="dropdownsData[field.id]"
we select by id {
"id": 17,
"name": "BMW",
"value": "BMW",
"models": [
"i3",
"i8",
"M3",
"M4",
"M5",
"M6",
"X1",
"X3",
"X4",
"X5",
"X6"
]
}
Answer the question
In order to leave comments, you need to log in
well, look.
1) well, it would be nice to return this information along with information about the field
formFields: [
{
name: 'my_field',
data: [/** your data **/],
class: 'moi_class',
type: 'input',
component: 'ui_input',
id: 1
},
{
name: 'brand',
data: [/** your data **/],
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 2
},
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question