I'm using VueSelect for address select. There are 3 select components for country, state, city.
With using v-model, it's working well to get the specified value instead of option object by using reduce prop. Here my problem is to not set default value by key value.
I expected that it set the default value by id like html select.
but it's showing the key value as it is, not being bound by the label value.
Hope you can make sense from my explanation.
Expecting like v-select of vuetify.
vuetify example
<template>
<div class="col-sm-6 ">
<v-select
v-model="address.country_id"
:options="countryOptions"
:reduce="country => country.id"
label="name"
@input="resetStateAndCity"
:resetOnOptionsChange="true"
/>
</div>
<div class="col-sm-6">
<v-select
v-model="address.state_id"
:options="stateOptions"
:reduce="state => state.id"
label="name"
@input="resetCity"
:resetOnOptionsChange="true"
/>
</div>
<div class="col-sm-6">
<v-select
v-model="address.city_id"
:options="cityOptions"
:reduce="city => city.id"
label="name"
:resetOnOptionsChange="true"
/>
</div>
</template>
<script>
import VSelect from 'vue-select'
export default {
components: {
VSelect
},
data: function () {
return {
address: {
city_id: null,
state_id: null,
country_id: null
},
countryOptions: [],
stateOptions: [],
cityOptions: []
}
},
mounted() {
this.$axios.get('/countries.json')
.then(response => {
this.countryOptions = response.data
})
},
methods: {
resetStateAndCity() {
if (!this.address.country_id) return
this.$axios.get(`/countries/${this.address.country_id}/states.json`)
.then(response => {
this.stateOptions = response.data
})
this.address.state_id = null
this.address.city_id = null
this.cityOptions = []
},
resetCity() {
if (!this.address.country_id || !this.address.state_id) return
this.address.city_id = null
this.$axios.get(`/countries/${this.address.country_id}/states/${this.address.state_id}/cities.json`)
.then(response => {
this.cityOptions = response.data
})
}
}
}
</script>