三级联动,随着越来越多的审美,出现了很多种,好多公司都仿着淘宝的三级联动 ,好看时尚,so我们公司也一样……为了贴代码方便,我把写在data里面省市区的json独立了出来,下载贴进去即可用,链接如下

首先页面显示如下:

然后我们县级所在地区会出现三级联动,如下:(以下是片段,背景色未截取)

这个张什么样,以什么形式出现,取决于贵公司的UI需求,我们公司是做成弹出层了。。然后背景色透明,这里为了节省流量,我只截取了一段,最后显示如下:

如果贵公司也跟我们需求一样,希望这个可以帮到你们。下面是在vue2项目中写的三级联动代码以及css样式:

  1. <template>
  2. <section class="myAddress">
  3. <section>
  4. <section class="cont" @click="choseAdd()">
  5. <section>
  6. <span>所在地区:{{Province?Province:''}} {{City?City:''}} {{District?District:''}}</span>
  7. </section>
  8. <img src="../../assets/main/right.png" alt="">
  9. <div style="clear: both"></div>
  10. </section>
  11. </section>
  12. <!-- 居住地址三级联动选项 -->
  13. <section class="showChose" v-show="showChose">
  14. <section class="address">
  15. <section class="title">
  16. <h4>居住地址</h4>
  17. <span @click="closeAdd()">×</span>
  18. </section>
  19. <section class="title">
  20. <div class="area" @click="provinceSelected()">
  21. {{Province?Province:info[province-1].name}}
  22. </div>
  23. <div class="area" @click="citySelected()" :class="City?'':'active'">
  24. {{City?City:'请选择'}}
  25. </div>
  26. <div class="area" @click="districtSelected()" :class="District?'':'active'" v-show="City">
  27. {{District?District:'请选择'}}
  28. </div>
  29. </section>
  30. <ul>
  31. <li class="addList" v-for="(v,k) in info"
  32. @click="getProvinceId(v.id, v.name, k)"
  33. v-show="showProvince"
  34. :class="v.selected ? 'active' : ''">{{v.name}}</li>
  35. <li class="addList" v-for="(v,k) in showCityList"
  36. @click="getCityId(v.id, v.name, k)"
  37. v-show="showCity"
  38. :class="v.selected ? 'active' : ''">{{v.name}}</li>
  39. <li class="addList" v-for="(v,k) in showDistrictList"
  40. @click="getDistrictId(v.id, v.name, k)"
  41. v-show="showDistrict"
  42. :class="v.selected ? 'active' : ''">{{v.name}}</li>
  43. </ul>
  44. </section>
  45. </section>
  46. <!-- 页面内容 -->
  47. <section class="cont">
  48. <span>详细地址:</span>
  49. <input type="text" v-model="address" placeholder=" 请填写详细地址">
  50. </section>
  51. </section>
  52. </template>
  53. <script>
  54. import {
  55. mapActions,
  56. mapGetters
  57. } from 'vuex';
  58. import api from './../../fetch/api.js'
  59. export default {
  60. name: 'address',
  61. data(){},此处的data直接下载json复制进去即可。http://www.cnblogs.com/lguow/p/9272563.html
  62. components: {
  63. MineHeader
  64. },
  65. computed: {
  66. ...mapGetters([
  67. 'BCcontextPathSrc',
  68. 'sessionId',
  69. 'token',
  70. ]),
  71. },
  72. methods: {
  73. choseAdd: function() {
  74. this.showChose = true;
  75. },
  76. closeAdd: function() {
  77. this.showChose = false;
  78. },
  79. _filter(add, name, code) {
  80. let result = [];
  81. for (let i = 0; i < add.length; i++) {
  82. if (code == add[i].id) {
  83. result = add[i][name];
  84. }
  85. }
  86. return result;
  87. },
  88. getProvinceId: function(code, input, index) {
  89. this.province = code;
  90. this.Province = input;
  91. this.showProvince = false;
  92. this.showCity = true;
  93. this.showDistrict = false;
  94. this.showCityList = this._filter(this.info, 'city', this.province);
  95. // 点击选择当前
  96. this.info.map(a => a.selected = false);
  97. this.info[index].selected = true;
  98. this.areaProvince = input;
  99. },
  100. provinceSelected: function() {
  101. // 清除市级和区级列表
  102. this.showCityList = false;
  103. this.showDistrictList = false;
  104. // 清除市级和区级选项
  105. this.City = false;
  106. this.District = false;
  107. // 选项页面的切换
  108. this.showProvince = true;
  109. this.showCity = false;
  110. this.showDistrict = false;
  111. },
  112. getCityId: function(code, input, index) {
  113. this.city = code;
  114. this.City = input;
  115. this.showProvince = false;
  116. this.showCity = false;
  117. this.showDistrict = true;
  118. this.showDistrictList = this._filter(this.showCityList, 'district', this.city);
  119. // 选择当前添加active
  120. this.showCityList.map(a => a.selected = false);
  121. this.showCityList[index].selected = true;
  122. this.areaCity = input;
  123. },
  124. citySelected: function() {
  125. this.showProvince = false;
  126. this.showCity = true;
  127. this.showDistrict = false;
  128. },
  129. getDistrictId: function(code, input, index) {
  130. this.district = code;
  131. this.District = input;
  132. // 选择当前添加active
  133. this.showDistrictList.map(a => a.selected = false);
  134. this.showDistrictList[index].selected = true;
  135. // 选取市区选项之后关闭弹层
  136. this.showChose = false;
  137. this.areaDistrict = input;
  138. },
  139. districtSelected: function() {
  140. this.showProvince = false;
  141. this.showCity = false;
  142. this.showDistrict = true;
  143. },
  144. saveProfile: function() {
  145. api.commonApi('后台接口', 这里是贵公司后台接口,按照你们公司的改了就好
  146. 'param_key={"head":{"TYPE":"ADD_UPD_INFO",' +
  147. '"SESSION_ID":"' + this.sessionId + '",' +
  148. '"TOKEN":"' + this.token + '","DEVICE_ID":""},' +
  149. '"param":{"PROVINCE":"' + this.areaProvince + '", ' +
  150. '"CITY":"' + this.areaCity + '", "COUNTY":"' + this.areaDistrict + '",' +
  151. '"ADDRESS": "' + this.address + '"}}')
  152. .then(res => {
  153. console.log(res.data);
  154. });
  155. }
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. .myAddress {
  161. width: 100%;
  162. background-color: white;
  163. border-top: 4px solid rgba(245, 245, 245, 1);
  164. color: #333;
  165. }
  166. .myAddress .cont {
  167. border-bottom: 1px solid rgba(245, 245, 245, 0.8);
  168. }
  169. .myAddress .cont span {
  170. display: inline-block;
  171. font-size: 0.28rem;
  172. color: #333;
  173. line-height: 0.88rem;
  174. margin-left: 0.32rem;
  175. }
  176. .myAddress .cont section {
  177. float: left;
  178. }
  179. .myAddress .cont img {
  180. float: right;
  181. width: 0.14rem;
  182. height: 0.24rem;
  183. margin: 0.32rem 0.32rem 0.32rem 0;
  184. }
  185. .showChose {
  186. width: 100%;
  187. height: 100%;
  188. position: fixed;
  189. top: 0;
  190. left: 0;
  191. z-index: 120;
  192. background: rgba(77, 82, 113, 0.8);
  193. }
  194. .address {
  195. position: absolute;
  196. bottom: 0;
  197. left: 0;
  198. z-index: 121;
  199. background: #fff;
  200. width: 100%;
  201. }
  202. .title h4 {
  203. display: inline-block;
  204. margin-left: 3.2rem;
  205. font-size: 0.32rem;
  206. line-height: 0.88rem;
  207. font-weight: normal;
  208. color: #999;
  209. }
  210. .title span {
  211. margin: 0.42rem 0 0 2.2rem;
  212. font-size: 0.45rem;
  213. line-height: 0.34rem;
  214. color: #D8D8D8;
  215. }
  216. .area {
  217. display: inline-block;
  218. font-size: 0.24rem;
  219. line-height: 0.88rem;
  220. margin-left: 0.42rem;
  221. color: #333;
  222. }
  223. .addList {
  224. padding-left: 0.32rem;
  225. font-size: 0.34rem;
  226. line-height: 0.88rem;
  227. color: #333;
  228. }
  229. /* 修改的格式 */
  230. .address ul {
  231. height: 100%;
  232. margin-left: 5%;
  233. max-height: 4.4rem;
  234. overflow: auto;
  235. }
  236. .address .title .active {
  237. color: #0071B8;
  238. border-bottom: 0.02rem solid #0071B8;
  239. }
  240. .address ul .active {
  241. color: #0071B8;
  242. }
  243. </style>

这样就完成了一个省市区的三级联动……悲催啊……整个项目里到处都是坑爹的UI坑爹的需求……

用Vue2仿京东省市区三级联动效果的更多相关文章

  1. vue仿京东省市区三级联动选择组件

    工作中需要一个盒京东购物车地址选择相似的一个省市区三级联动选择组件,google查了下都是下拉框形式的,于是自己写了一个,希望对使用vue开发项目的朋友有帮助,显示效果如下:使用vue2.0开发 ht ...

  2. Ajax来实现下拉框省市区三级联动效果(服务端基于express)

    //服务端JS代码: //提供服务端的处理 const express = require('express'); const fs = require('fs'); const app = expr ...

  3. WheelView实现省市区三级联动(数据库实现版本号附带完整SQL及数据)

    近期在实现收货地址功能,用到了省市区三级联动效果,网上找到一般都是xml或json.数据源陈旧改动麻烦.改动了一下使用数据库方式实现了一下 数据源解决.因为数据量比較大通过初始化批量运行SQL的方式不 ...

  4. js之省市区(县)三级联动效果

    省市区(县)三级联动效果,是我们软件开发比较常用的,特别是对一些crm,erp之类,当然也包括其他的后台管理系统,基本都涉及到,今天贴出这个常用的,方便个人复用和大家使用 <!DOCTYPE h ...

  5. jQuery省市区三级联动插件

    体验效果:http://hovertree.com/texiao/bootstrap/4/支持PC和手机移动端. 手机扫描二维码体验效果: 代码如下: <!DOCTYPE html> &l ...

  6. 省市区三级联动 pickerView

    效果图 概述 关于 省市区 三级联动的 pickerView,我想大多数的 iOS 开发者应该都遇到过这样的需求.在遇到这样的需求的时候,大多数人都会觉的这个很复杂,一时无从下手.其实真的没那么复杂. ...

  7. QQ JS省市区三级联动

    如下图: 首先写一个静态的页面: <!DOCTYPE html> <html> <head> <title>QQ JS省市区三级联动</title ...

  8. Android中使用开源框架citypickerview实现省市区三级联动选择

    1.概述 记得之前做商城项目,需要在地址选择中实现省市区三级联动,方便用户快速的填写地址,当时使用的是一个叫做android-wheel 的开源控件,当时感觉非常好用,唯一麻烦的是需要自己整理并解析省 ...

  9. PHPOffice/PHPExcel生成省市区三级联动的excel表格

    最近公司需要用到一个省市区三级联动的excel表格,但是数据都在数据库,又太多,人工不好制作,就让我这个phper来帮忙啦. 主要用到的是excel的定义名称,数据验证.其中数据验证的列表只能是一列或 ...

随机推荐

  1. python numpy和pandas做数据分析时去掉科学记数法显示

    1.Numpy import numpy as np np.set_printoptions(suppress=True, threshold=np.nan) suppress=True 取消科学记数 ...

  2. 用 pdf.js兼容部分安卓显示PDF在线预览 时,a标签直接链接参数文件不能含中文的解决办法

    例子: 项目部署在 Tomcat 上的: <a href="../generic/web/viewer.html?file=doc/register/要显示的文件.pdf" ...

  3. CollectionUtils工具类的常用方法

    集合判断:  例1: 判断集合是否为空: CollectionUtils.isEmpty(null): true CollectionUtils.isEmpty(new ArrayList()): t ...

  4. Java Swing 编程 JComboBox 显示不全问题。

    最近在做Java Swing编程一个小例子.然后遇到JComboBox 宽度固定,而下拉列表比较长,导致显示不全的问题. 解决的思路想到两种,1:下拉列表当显示不全的时候,换行显示.2:在下拉列表停几 ...

  5. linux常用命令及使用技巧(二)

    ls显示指定工作目录下的内容,同windows中的dir命令 pwd命令显示当前工作目录 date命令,显示或修改系统时间与日期 passwd命令,设置用户密码 su命令改变用户身份 clear命令, ...

  6. 使用Python批量下载Plus上的Podcast

    Plus是一个介绍数学之美与实际应用的网络杂志,其中包含了数学知识.轶闻趣事.历史典故等许多精彩的内容.该杂志恰好有一个Podcast栏目,提供了不少采访与讲座的mp3音频.于是, 我使用Python ...

  7. Linq to Object原理

    using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace ...

  8. GO语言一行代码实现反向代理

    本文,介绍了什么是反向代理,如何用go语言实现反向代理. 至于他的标题, "GO语言一行代码实现反向代理 | Writing a Reverse Proxy in just one line ...

  9. 实现定时备份mysql数据库并把备份数据库邮件发送

    一.先来看备份mysql数据库的命令 1 mysqldump -u root --password=root --database abcDataBase > c:/abc_backup.sql ...

  10. Snakes 的 Naïve Graph

    题解: 首先分析一下这个问题 发现等价于是求n之内与n互素的数的个数,即欧拉函数 这个可以线性筛 但发现还应该减去$x^2==1$的情况 这个东西不是那么好处理 考虑用中国剩余定理拆 因为$p1^{a ...