<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<style>
    .selBoxList{width:100%;margin-top:50px;text-align:center;}
    .selBoxList .selSt{min-width:100px;display:inline-block;position:relative;;}
    .selBoxList .selSt .current{width:100%;padding:0 10px;font-size:16px;line-height:30px;cursor:pointer;float:left;border:1px solid #ccc;background:#fff;box-sizing: border-box;position:relative;z-index: 2;}
    .selBoxList .selSt .box{width:100%;position:absolute;left:0;top:30px;border:1px solid #ccc;max-height:300px;overflow:auto;box-sizing: border-box;}
    .selBoxList .selSt .box span{width:100%;font-size:16px;line-height:30px;cursor:pointer;border-top:1px solid #ccc;float:left;}
    .selBoxList .selSt .box span:hover{background:#f1f1f1;}
</style>
</head>
<body>
<div class="selBoxList">
    <span class="selSt selProvince">
        <span class="current" @click="toggleSelect(0)"><span v-if="!proIndex">--请选择--</span><span v-if="proIndex">{{cityArr[proIndex].name}}</span></span>
        <span class="box" v-show="showSelect === 0">
            <span v-for="n in cityArr.length" @click="setOption('proIndex', $index)">{{cityArr[n].name}}</span>
        </span>
    </span>
    <span class="selSt selCity">
        <span class="current" @click="toggleSelect(1)"><span v-if="!cityIndex">--请选择--</span><span v-if="cityIndex">{{cityArr[proIndex].sub[cityIndex].name}}</span></span>
        <span class="box" v-show="showSelect === 1">
            <span v-if="cityArr[proIndex].sub.length" v-for="n in cityArr[proIndex].sub.length" @click="setOption('cityIndex', $index)">{{cityArr[proIndex].sub[n].name}}</span>
        </span>
    </span>
    <span class="selSt selArea">
        <span class="current" @click="toggleSelect(2)"><span v-if="!areaIndex">--请选择--</span><span v-if="areaIndex">{{cityArr[proIndex].sub[cityIndex].sub[areaIndex].name}}</span></span>
        <span class="box" v-show="showSelect === 2">
            <span v-if="cityArr[proIndex].sub[cityIndex].sub.length" v-for="n in cityArr[proIndex].sub[cityIndex].sub.length" @click="setOption('areaIndex', $index)">{{cityArr[proIndex].sub[cityIndex].sub[n].name}}</span>
        </span>
    </span>
</div>
<script src="http://passport.baidu.com/js/sitedata_bas.js" charset="GBK"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<script>
var vm = new Vue({
    el: 'body',
    data: {
        cityArr: arrCity,
        proIndex: 0,
        cityIndex: 0,
        areaIndex: 0,
        showSelect: ''
    },
    methods: {
        setOption: function(type, index){
            this[type] = index;
            if(type === 'proIndex'){
                this.cityIndex = 0;
                this.areaIndex = 0;
            }
            if(type === 'cityIndex'){
                this.areaIndex = 0;
            }
            this.showSelect = '';
        },
        toggleSelect: function(n){
            if(this.showSelect === n){
                this.showSelect = '';
            }else{
                this.showSelect = n;
            }
        }
    }
})
</script>
</body>
</html>

来自:http://www.qdfuns.com/notes/15309/d4e088dd33ec99fb8811202bb879065e.html

  

用Vue.js来实现城市三级联动的更多相关文章

  1. vue 使用element-ui实现城市三级联动

    <template> <div> <el-select v-model="prov" style="width:167px;margin-r ...

  2. 全国城市三级联动 html+js

    全国城市三级联动,没有css,所以屏幕的自适应必须自己想办法,手机端慎用(最好不要用,因为有些我也说不出的展示问题). html页面 <!DOCTYPE html> <html> ...

  3. 城市三级联动 AJAX-原生js封装

    话不多说我们先来一张效果图给大家看一下: html代码如下: <!DOCTYPE html><html lang="en"><head> < ...

  4. jquery 城市三级联动

    js代码 /*城市三级联动 * @method cityChange * @param allProvince,allCity,allDistrict */ function cityChange(p ...

  5. 转: javascript实现全国城市三级联动菜单代码

    <html> <head> <title>js全国城市三级联动菜单代码_B5教程网</title> <meta http-equiv=" ...

  6. js 实现全国省市区三级联动

    效果: index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /& ...

  7. vue+element实现省区市三级联动以及详细地址的输入

    Vue+elementui实现省区市三级联动+详细地址的输入 详细需求,需要手动更改用户所在的地址. 安装依赖项 npm install element-china-area-data -S 在组建中 ...

  8. JS 实现的年月日三级联动

    js文件 SYT="-请选择年份-"; SMT="-请选择月份-"; SDT="-请选择日期-"; BYN=50;//年份范围往前50年 A ...

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

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

随机推荐

  1. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

  2. SPOJ 7258 SUBLEX 后缀数组 + 二分答案 + 前缀和

    Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) f ...

  3. [BJWC2011]禁忌 AC 自动机 概率与期望

    #include<cstdio> #include<algorithm> #include<cstring> #include<string> #inc ...

  4. 隐藏div,文本框角圆滑,消除外边框

    #div_1 /*将div设置完成,并且隐藏,当需要的时候对其属性值进行修改*/ { height: 36px; width: 1099px; background-color: #F0DFDF; m ...

  5. Hdu 4930 斗地主

    模拟题,只是想纪念下,WA到死了…… 看到好多代码都好长,其实想说不用这么暴力. #include <iostream> #include <cstdio> #include ...

  6. CRC校验原理及步骤

    什么是CRC校验? CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并 ...

  7. 【Codeforces Beta Round #45 D】Permutations

    [题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...

  8. ZOJ 2588 Burning Bridges(无向连通图求割边)

    题目地址:ZOJ 2588 由于数组开小了而TLE了..这题就是一个求无向连通图最小割边.仅仅要推断dfn[u]是否<low[v],由于low指的当前所能回到的祖先的最小标号,增加low[v]大 ...

  9. Hive的单节点集群详细启动步骤

    说在前面的话, 在这里,推荐大家,一定要先去看这篇博客,如下 再谈hive-1.0.0与hive-1.2.1到JDBC编程忽略细节问题 Hadoop Hive概念学习系列之hive三种方式区别和搭建. ...

  10. Android ViewPager实现多个图片水平滚动

    1.示意图                       2.实现分析 (1).xml配置 <!-- 配置container和pager的clipChildren=false, 并且指定margi ...