Vue+ElementUI 实现三级省市联动(附带数据)

HTML部分:
在这里插入图片描述
js部分:

data
在这里插入图片描述
methods方法部分
在这里插入图片描述
计算属性computed

 computed: {
                getTotal(){
                    return this.myCarts.reduce((a,b) =>{
                        return a + b.price * b.quantity;
                },0);
                },

                getAddressProvince(value){
                    value = this.form.addressProvince;

                    for(y in this.CityInfo){
                        if(this.CityInfo[y].value == value){
                            return value = this.CityInfo[y].label;
                        }
                    }
                },
                getAddressCity(value){
                    value = this.form.addressCity;

                    for(y in this.CityInfo){
                        for(z in this.CityInfo[y].children){
                            if(this.CityInfo[y].children[z].value == value && value!=undefined){
                                return value = this.CityInfo[y].children[z].label;
                            }
                        }
                    }
                },

                getAddressDistrict(value){
                    value = this.form.addressDistrict;

                    for(y in this.CityInfo){
                        for(z in this.CityInfo[y].children){
                            for(i in this.CityInfo[y].children[z].children){
                                if(this.CityInfo[y].children[z].children[i].value == value && value!=undefined){
                                    return value = this.CityInfo[y].children[z].children[i].label;
                                }
                            }
                        }
                    }
                },

完整代码和省市区数据文件传送门


欢迎关注公众号Java技术大本营,会不定期分享BAT面试资料等福利。

在这里插入图片描述


你可以使用 Vue 和 Element UI 来实现下拉框的二级联动。下面是一个简单的示例: 首先,在你的 Vue 组件中引入相关的库和组件: ```javascript <template> <div> <el-select v-model="selectedProvince" @change="handleProvinceChange"> <el-option v-for="province in provinces" :key="province" :label="province" :value="province"></el-option> </el-select> <el-select v-model="selectedCity"> <el-option v-for="city in cities" :key="city" :label="city" :value="city"></el-option> </el-select> </div> </template> <script> export default { data() { return { selectedProvince: '', selectedCity: '', provinces: ['省份1', '省份2', '省份3'], // 替换成你的省份数据 cities: { '省份1': ['城市1', '城市2', '城市3'], // 替换成你的城市数据 '省份2': ['城市4', '城市5', '城市6'], '省份3': ['城市7', '城市8', '城市9'] } }; }, methods: { handleProvinceChange() { this.selectedCity = ''; // 清空已选择的城市 } } }; </script> ``` 在上面的示例中,我们使用了两个 `el-select` 组件来展示省份和城市的下拉框。`provinces` 数组存储了所有的省份数据,`cities` 对象存储了每个省份对应的城市数据。当选择省份时,`handleProvinceChange` 方法会被调用,清空已选择的城市并更新城市下拉框的选项。 请注意,上述示例中的省份和城市数据都是静态的,你需要根据实际情况进行替换。你可以从后端或其他数据源中获取数据,并将其动态地传递给组件。 希望这个示例能帮助到你实现下拉框的二级联动!如有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值