最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue2仿淘寶實現(xiàn)省市區(qū)三級聯(lián)動

 更新時間:2020年04月15日 14:31:52   作者:趙海辛  
這篇文章主要為大家詳細(xì)介紹了Vue2仿淘寶實現(xiàn)省市區(qū)三級聯(lián)動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

三級聯(lián)動,隨著越來越多的審美,出現(xiàn)了很多種,好多公司都仿著淘寶的三級聯(lián)動 ,好看時尚,so我們公司也一樣……為了貼代碼方便,我把寫在data里面省市區(qū)的json獨立了出來,下載貼進(jìn)去即可用,鏈接如下:vue.json(這個直接是個data,放入你的vue2項目中即可。(因為我的項目是用的vue2,所以,其他的屬性跟博客內(nèi)容是吻合的。請配合博客再下載此json))。

首先頁面顯示如下:

然后我們縣級所在地區(qū)會出現(xiàn)三級聯(lián)動,如下:(以下是片段,背景色未截取)

這個張什么樣,以什么形式出現(xiàn),取決于貴公司的UI需求,我們公司是做成彈出層了。。然后背景色透明,這里為了節(jié)省流量,我只截取了一段,最后顯示如下:

如果貴公司也跟我們需求一樣,希望這個可以幫到你們。下面是在vue2項目中寫的三級聯(lián)動代碼以及css樣式:
<template>

 <section class="myAddress">
  <section>
   <section class="cont" @click="choseAdd()">
    <section>
     <span>所在地區(qū):{{Province?Province:''}} {{City?City:''}} {{District?District:''}}</span>
    </section>
    <img src="../../assets/main/right.png" alt="">
    <div style="clear: both"></div>
   </section>
  </section>
  <!-- 居住地址三級聯(lián)動選項 -->
  <section class="showChose" v-show="showChose">
   <section class="address">
   <section class="title">
    <h4>居住地址</h4>
    <span @click="closeAdd()">×</span>
   </section>
   <section class="title">
    <div class="area" @click="provinceSelected()">
     {{Province?Province:info[province-1].name}}
    </div>
    <div class="area" @click="citySelected()" :class="City?'':'active'">
     {{City?City:'請選擇'}}
    </div>
    <div class="area" @click="districtSelected()" :class="District?'':'active'" v-show="City">
     {{District?District:'請選擇'}}
    </div>
   </section>
   <ul>
    <li class="addList" v-for="(v,k) in info" 
     @click="getProvinceId(v.id, v.name, k)" 
     v-show="showProvince" 
     :class="v.selected ? 'active' : ''">{{v.name}}</li>
    <li class="addList" v-for="(v,k) in showCityList" 
     @click="getCityId(v.id, v.name, k)" 
     v-show="showCity" 
     :class="v.selected ? 'active' : ''">{{v.name}}</li>
    <li class="addList" v-for="(v,k) in showDistrictList" 
     @click="getDistrictId(v.id, v.name, k)" 
     v-show="showDistrict" 
     :class="v.selected ? 'active' : ''">{{v.name}}</li>
    </ul>
   </section>
  </section>
  <!-- 頁面內(nèi)容 -->
  <section class="cont">
   <span>詳細(xì)地址:</span>
   <input type="text" v-model="address" placeholder=" 請?zhí)顚懺敿?xì)地址">
  </section>
 </section>
</template>
<script>
 import {
   mapActions,
   mapGetters
 } from 'vuex';
 import api from './../../fetch/api.js'
 export default {
  name: 'address',
  data(){},此處的data直接下載json復(fù)制進(jìn)去即可。http://download.csdn.net/detail/zhaohaixin0418/9862255。
  components: {
   MineHeader
  },
  computed: {
    ...mapGetters([
     'BCcontextPathSrc',
     'sessionId',
     'token',
    ]),
 },
 methods: {
  choseAdd: function() {
   this.showChose = true;
  },
  closeAdd: function() {
   this.showChose = false;
  },
  _filter(add, name, code) {
   let result = [];
   for (let i = 0; i < add.length; i++) {
    if (code == add[i].id) {
     result = add[i][name];
    }
   }
   return result;
  },
  getProvinceId: function(code, input, index) {
   this.province = code;
   this.Province = input;
   this.showProvince = false;
   this.showCity = true;
   this.showDistrict = false;
   this.showCityList = this._filter(this.info, 'city', this.province);
   // 點擊選擇當(dāng)前
   this.info.map(a => a.selected = false);
   this.info[index].selected = true;
   this.areaProvince = input;
  },
  provinceSelected: function() {
   // 清除市級和區(qū)級列表
   this.showCityList = false;
   this.showDistrictList = false;
   // 清除市級和區(qū)級選項
   this.City = false;
   this.District = false;
   // 選項頁面的切換
   this.showProvince = true;
   this.showCity = false;
   this.showDistrict = false;
  },
  getCityId: function(code, input, index) {
   this.city = code;
   this.City = input;
   this.showProvince = false;
   this.showCity = false;
   this.showDistrict = true;
   this.showDistrictList = this._filter(this.showCityList, 'district', this.city);
   // 選擇當(dāng)前添加active
   this.showCityList.map(a => a.selected = false);
   this.showCityList[index].selected = true;
   this.areaCity = input;
  },
  citySelected: function() {
   this.showProvince = false;
   this.showCity = true;
   this.showDistrict = false;
  },
  getDistrictId: function(code, input, index) {
   this.district = code;
   this.District = input;
   // 選擇當(dāng)前添加active
   this.showDistrictList.map(a => a.selected = false);
   this.showDistrictList[index].selected = true;
   // 選取市區(qū)選項之后關(guān)閉彈層
   this.showChose = false;
   this.areaDistrict = input;
  },
  districtSelected: function() {
   this.showProvince = false;
   this.showCity = false;
   this.showDistrict = true;
  },
  saveProfile: function() {
   api.commonApi('后臺接口', 這里是貴公司后臺接口,按照你們公司的改了就好
     'param_key={"head":{"TYPE":"ADD_UPD_INFO",' +
     '"SESSION_ID":"' + this.sessionId + '",' +
     '"TOKEN":"' + this.token + '","DEVICE_ID":""},' +
     '"param":{"PROVINCE":"' + this.areaProvince + '", ' +
     '"CITY":"' + this.areaCity + '", "COUNTY":"' + this.areaDistrict + '",' +
     '"ADDRESS": "' + this.address + '"}}')
     .then(res => {
    console.log(res.data);
  });
  }
 }
 }
</script>
<style scoped>
 .myAddress {
  width: 100%;
  background-color: white;
  border-top: 4px solid rgba(245, 245, 245, 1);
  color: #333;
 }
 .myAddress .cont {
  border-bottom: 1px solid rgba(245, 245, 245, 0.8);
 }
 .myAddress .cont span {
  display: inline-block;
  font-size: 0.28rem;
  color: #333;
  line-height: 0.88rem;
  margin-left: 0.32rem;
 }
 .myAddress .cont section {
  float: left;
 }
 .myAddress .cont img {
  float: right;
  width: 0.14rem;
  height: 0.24rem;
  margin: 0.32rem 0.32rem 0.32rem 0;
 }
 .showChose {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 120;
  background: rgba(77, 82, 113, 0.8);
 }
 .address {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 121;
  background: #fff;
  width: 100%;
 }
 .title h4 {
  display: inline-block;
  margin-left: 3.2rem;
  font-size: 0.32rem;
  line-height: 0.88rem;
  font-weight: normal;
  color: #999;
 }
 .title span {
  margin: 0.42rem 0 0 2.2rem;
  font-size: 0.45rem;
  line-height: 0.34rem;
  color: #D8D8D8;
 }
 .area {
  display: inline-block;
  font-size: 0.24rem;
  line-height: 0.88rem;
  margin-left: 0.42rem;
  color: #333;
 }
 .addList {
  padding-left: 0.32rem;
  font-size: 0.34rem;
  line-height: 0.88rem;
  color: #333;
 }
 /* 修改的格式 */
 .address ul {
  height: 100%;
  margin-left: 5%;
  max-height: 4.4rem;
  overflow: auto;
 }
 .address .title .active {
  color: #0071B8;
  border-bottom: 0.02rem solid #0071B8;
 }
 .address ul .active {
  color: #0071B8;
 }
</style>

這樣就完成了一個省市區(qū)的三級聯(lián)動。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Element-ui自定義table表頭、修改列標(biāo)題樣式、添加tooltip、:render-header使用

    Element-ui自定義table表頭、修改列標(biāo)題樣式、添加tooltip、:render-header使用

    這篇文章主要介紹了Element-ui自定義table表頭、修改列標(biāo)題樣式、添加tooltip、:render-header使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • Vue3中?引入Ant?Design的操作方法

    Vue3中?引入Ant?Design的操作方法

    Ant?Design?是一個開源庫,可讓您創(chuàng)建吸引人的響應(yīng)式網(wǎng)站。如果您想使用經(jīng)過充分測試且易于學(xué)習(xí)的框架,那么它是您下一個項目的絕佳選擇,這篇文章主要介紹了如何在?Vue?3?中使用?Ant?Design,需要的朋友可以參考下
    2023-04-04
  • vue前端如何將任意文件轉(zhuǎn)為base64傳給后端

    vue前端如何將任意文件轉(zhuǎn)為base64傳給后端

    這篇文章主要介紹了vue前端如何將任意文件轉(zhuǎn)為base64傳給后端問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue項目動態(tài)設(shè)置iframe元素高度的操作代碼

    vue項目動態(tài)設(shè)置iframe元素高度的操作代碼

    在現(xiàn)代Web開發(fā)中,iframe元素常用于嵌入外部內(nèi)容到當(dāng)前網(wǎng)頁中,比如在線文檔、視頻播放器或是廣告,Vue框架提供了強大的工具來解決這個問題,通過動態(tài)設(shè)置iframe元素的高度,我們可以確保頁面布局既美觀又高效,本文給大家介紹了vue項目動態(tài)設(shè)置iframe元素高度的操作
    2024-10-10
  • vue項目中的.env文件加載方式

    vue項目中的.env文件加載方式

    在Vue項目中,通過.env文件配置環(huán)境變量,支持不同環(huán)境下加載不同配置,Vite通過import.meta.env向應(yīng)用暴露環(huán)境變量,支持基本URL、開發(fā)環(huán)境和生產(chǎn)環(huán)境識別等,.env文件可設(shè)置環(huán)境優(yōu)先級,修改后需重啟生效,TypeScript可通過增加文件獲取智能提示
    2024-10-10
  • 解決Vue在封裝了Axios后手動刷新頁面攔截器無效的問題

    解決Vue在封裝了Axios后手動刷新頁面攔截器無效的問題

    這篇文章主要介紹了解決VUE在封裝了Axios后手動刷新頁面攔截器無效的問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-11-11
  • Vue使用Markdown文檔的示例

    Vue使用Markdown文檔的示例

    本文主要介紹了Vue使用Markdown文檔的示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • vant 時間選擇器--開始時間和結(jié)束時間實例

    vant 時間選擇器--開始時間和結(jié)束時間實例

    這篇文章主要介紹了vant 時間選擇器--開始時間和結(jié)束時間實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Vue操作數(shù)組的幾種常用方法小結(jié)

    Vue操作數(shù)組的幾種常用方法小結(jié)

    本文主要介紹了Vue操作數(shù)組的幾種常用方法小結(jié),主要包括map、filter、forEach、find 和 findIndex 、some 和 every、includes、Array.from這幾種方法,感興趣的可以了解一下
    2023-09-09
  • Vue3?中的模板語法小結(jié)

    Vue3?中的模板語法小結(jié)

    Vue 使用一種基于 HTML 的模板語法,使我們能夠聲明式地將其組件實例的數(shù)據(jù)綁定到呈現(xiàn)的 DOM 上,這篇文章主要介紹了Vue3?中的模板語法,需要的朋友可以參考下
    2023-03-03

最新評論

嘉义县| 喜德县| 青田县| 德庆县| 台中市| 边坝县| 会泽县| 雅江县| 沅陵县| 长葛市| 栖霞市| 盖州市| 太保市| 重庆市| 普兰县| 通城县| 青岛市| 临沂市| 金平| 太原市| 北宁市| 和田县| 湾仔区| 新安县| 宽甸| 广东省| 彩票| 天门市| 杂多县| 汝州市| 永胜县| 新巴尔虎左旗| 新干县| 宕昌县| 涟源市| 武山县| 溆浦县| 江孜县| 丰原市| 和龙市| 昌乐县|