【发布时间】:2018-01-28 05:41:16
【问题描述】:
我有一个问题,用户需要先选择国家,然后是州,然后是城市。现在我已经在国家和州上设置了@change 事件,一旦用户选择国家,它就会获取州,并且也会触发州上的@change,并且由于我有 state_id = '',现在我的 getCities 函数失败了。
<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
}
}
【问题讨论】:
标签: javascript vue.js vuejs2