I have a problem where user needs to select countries first and then states and then cities. Now I have setup @change event on countries and states, as soon as the user selects country it fetches states and also @change on states is also triggered, and since I have state_id = '', now my getCities function fails.
<select v-model="country_id" @change="getStates()">
<option v-for="country in countries" :value="country.id">{{ country.name }}</option>
</select>
<select v-model="state_id" @change="getCities()">
<option v-for="state in states" :value="state.id">{{ state.name }}</option>
</select>
data(){
return{
countries: [],
states: [],
cities: [],
country_id: '',
state_id: '',
city_id: ''
}
},
mounted(){
getCountries();
},
methods:{
getCountries(){
// this.countries = response.data
}
geStates(){
//get states where country_id = this.country_id
},
getCities(){
//get cities where state_id = this.state_id
//once country is selected even this is getting triggered
}
}