当前位置: 首页 > news >正文

vue中组件传值 引用页面与组件页面绑定参数 vue省市地区街道级联选择组件

在做后台的时候需要用到地区级联选择器 然后就自己封装了一个

其中 组件页面中

export default {props: {		//使用value接收引用页面的绑定值value: [String]},watch: {value: {handler(val) {//val 以及 this.value 都可以获取到引用页面的绑定值},deep: true,immediate: true}},
}
//this.$emit("input", this.changeForm()); 这句代码是给引用页面绑定值返回内容

完整地区json文件在网盘中

链接:https://pan.quark.cn/s/0b70e60fd377
提取码:4sSe

下面是完整代码:

引用页面中

<select-address v-model="form.applicableRange"/>

main.js中注册组件

import SelectAddress from '@/components/SelectAddress'Vue.component('SelectAddress', SelectAddress)

组件页面

<template><div class="selectAddress"><el-form :model="form"><el-select v-model="form.provincial" @change="updateProvincials()" clearableplaceholder="请选择省份"><el-option v-for="provincial in provincials" :key="provincial.label" :value="provincial.label":label="provincial.label"/></el-select><el-select v-model="form.municipal" @change="updateMunicipals()"placeholder="请选择城市"><el-option v-for="municipal in municipals" :key="municipal.label" :value="municipal.label":label="municipal.label"/></el-select><el-select v-model="form.regional" @change="updateRegionals()"placeholder="请选择地区"><el-option v-for="regional in regionals" :key="regional.label" :value="regional.label":label="regional.label"/></el-select><el-select v-model="form.streets" @change="updateStreetss()"placeholder="请选择街道"><el-option v-for="streets in streetss" :key="streets.label" :value="streets.label" :label="streets.label"/></el-select></el-form></div>
</template>
<script>
const options = require("@/assets/images/pcas-code.json");
export default {props: {value: [String]},data() {return {form: {provincial: null,municipal: null,regional: null,streets: null,},provincials: options,municipals: [],regionals: [],streetss: [],}},watch: {value: {handler(val) {if (val) {const list = this.value.split(' ');if(list.length == 1){this.form.provincial = list[0];this.updateProvincials();}else if(list.length == 2){this.form.provincial = list[0];this.updateProvincials();this.form.municipal = list[1];this.updateMunicipals();}else if(list.length == 3){this.form.provincial = list[0];this.updateProvincials();this.form.municipal = list[1];this.updateMunicipals();this.form.regional = list[2];this.updateRegionals();}} else {this.reset();return [];}},deep: true,immediate: true}},mounted() {},created() {},computed: {},methods: {reset() {this.form = {provincial: null,municipal: null,regional: null,streets: null}},updateProvincials() {this.form.municipal = "";this.form.regional = "";this.form.streets = "";this.municipals = [];this.regionals = [];this.streetss = [];this.$emit("input", this.changeForm());if(this.form.provincial){this.municipals = this.provincials.find(provincial => provincial.label == this.form.provincial).children;}},updateMunicipals() {this.form.regional = "";this.form.streets = "";this.regionals = [];this.streetss = [];this.$emit("input", this.changeForm());this.regionals = this.municipals.find(municipal => municipal.label == this.form.municipal).children;},updateRegionals() {this.form.streets = "";this.streetss = [];this.$emit("input", this.changeForm());this.streetss = this.regionals.find(regional => regional.label == this.form.regional).children;},updateStreetss() {this.$emit("input", this.changeForm());},changeForm(){let applicableRange = "";if(this.form.provincial){applicableRange = this.form.provincial}if(this.form.provincial && this.form.municipal){applicableRange = this.form.provincial + " " + this.form.municipal}if(this.form.provincial && this.form.municipal && this.form.regional){applicableRange = this.form.provincial + " " + this.form.municipal + " " + this.form.regional}if(this.form.provincial && this.form.municipal && this.form.regional && this.form.streets){applicableRange = this.form.provincial + " " + this.form.municipal + " " + this.form.regional + " " + this.form.streets}return applicableRange;}},
}
</script><style scoped lang="scss">
.el-select {width: 18%;margin-left: 1%;
}
</style>
http://www.lryc.cn/news/208121.html

相关文章:

  • componentDidMount只执行一次的解决方法
  • React之diff原理
  • ElasticSearch中关于Nasted嵌套查询的介绍:生动案例,通俗易懂,彻底吸收
  • 系列二、Spring的优缺点是什么
  • ESP32网络开发实例-HTTP-GET请求
  • PHP:json_encode和json_decode用法
  • Kafka-Java二:Spring配置kafka消息发送端的缓冲区
  • 【ArcGIS模型构建器】05:批量为多个矢量数据添加相同的字段
  • 坤坤的悲伤生活
  • 职业技术认证:《研发效能(DevOps)工程师》——开启职业发展新篇章
  • gin 框架出现runtime error: index out of range [0] with length 0
  • 【高阶数据结构】B树
  • Android-Framework 应用间跳转时,提供 Android Broadcast 通知
  • 【Javascript】函数返回值的作用
  • 蓝桥杯 Java k倍区间
  • 万宾科技亮相2023中国传感器与应用技术大会,创始人CEO发表演讲
  • #力扣:LCP 06. 拿硬币@FDDL
  • 【Node.js】暴露自定义响应头和预检请求的时机
  • 包管理工具与配置文件package.json
  • uni-app:解决异步请求返回值问题
  • <多线程章节七>wait() 和 notify()
  • 竹云产品入选《2023年度上海市网络安全产业创新攻关成果目录》
  • 客户端负载均衡策略:loadBalancer,ribbon
  • canvas基础3 -- 交互
  • Flutter——最详细(Scaffold)使用教程
  • C语言编写图形化界面-创建按钮-为其指定样式
  • C++并发与多线程(7) | 创建多个线程时数据共享的问题
  • 进程间通信(匿名管道、命名管道、消息队列、共享内存、信号量、信号、Socket)
  • 浅谈中国汽车充电桩行业市场状况及充电桩选型的介绍
  • Postgresql在jdbc处理bit字段的解决方案