Answer the question
In order to leave comments, you need to log in
How to correctly load data in select?
Made some dropdown 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>
<script>
import axios from 'axios';
export default {
props: [
"options",
"defaultValue",
"showSearch",
"inputPlaceholder"
],
data() {
return {
toggle: false,
value: "",
search: ""
};
},
watch: {
toggle: function (val) {
if(val === false) {
this.search = '';
}
}
},
methods: {
selectedItem(value) {
console.log(value)
}
}
}
</script>
<template>
<div>
<div v-for="(field, index) in formFields" :key="index">
<ui_input v-if="field.type == 'input'" v-model="input" @change="change($event)"></ui_input>
<dropdown :id="field.id" v-else-if="field.type == 'select'" :options="getAuto" default-value="Make a choice" show-search="true" input-placeholder="Выберите"></dropdown>
</div>
</div>
</template>
formFields: [
{
name: 'my_field',
class: 'moi_class',
type: 'input',
component: 'ui_input',
id: 'moi_id1'
},
{
name: 'brand',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 'moi_id2'
},
{
name: 'model',
class: 'moi_class',
type: 'select',
component: 'dropdown',
id: 'moi_id4'
}
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question