【问题标题】:Try to show values through vue js with laravel in drop down尝试在下拉菜单中使用 laravel 通过 vue js 显示值
【发布时间】: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


【解决方案1】:

@change='getCities()' 似乎存在语法错误,这将立即调用 getCities,您应该改为使用 @change='getCities'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 1970-01-01
    • 2015-04-02
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多