【发布时间】:2020-09-30 10:57:15
【问题描述】:
尝试在 laravel 7 中通过 vue.js 从数据库获取的下拉列表中显示国家/地区。国家/地区未显示在下拉列表中。
模板代码:
<template>
<div class="col-md-6 pull-right">
<label>Country of Birth </label>
<select name="birth_county" v-model='country' @change='getCities()'>
<option value="" selected disabled>Select country</option>
<option v-for='data in countries' :value='data.id'>{{ data.name }}</option>
</select>
</div>
</template>
脚本代码:
<script>
export default {
data(){
return {
country:0,
countries:[],
city:0,
cities:[]
}
},
methods:{
getCountries: function (){
axios.get('/get-countries')
.then(function (response){
this.countries = response.data;
}.bind(this));
},
getCities: function (){
axios.get('/get-cities', {
params: {
id: this.country
}
})
.then(function (response){
this.cities = response.data;
}.bind(this))
}
},
created: function () {
this.getCountries()
}
}
</script>
我正在尝试在下拉列表中显示国家/地区。
【问题讨论】:
-
您的回复似乎有问题。你能发布你从
/get-countries得到的回复吗? -
我成功显示了国家,但现在我没有显示城市。有一个问题。我不知道是什么..??
标签: javascript vue.js laravel-7