精华内容
下载资源
问答
  • vue实现城市选择,带拼音选择搜索,可以多次反复使用,数据直接请求本地的资源json数据直接请求本地的资源json
  • 主要介绍了vue实现城市列表选择功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
  • 1、实现头部搜索城市功能(v-if判断input不为空时,searchaction搜索城市结果列表块元素为true,indexof查找数据中的关键字) 2、遍历数组找出hot为true的热门城市 3、遍历数据,charAt(0)获取城市名称拼音的首拼...

    还是照旧加前提:页面极丑!请忽略,咱们看功能就行,懒得写样式了

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    前提:安装vue-cli vuex axios

    目标:
    1、实现头部搜索城市功能(v-if判断input不为空时,searchaction搜索城市结果列表块元素为true,indexof查找数据中的关键字)
    2、遍历数组找出hot为true的热门城市
    3、遍历数据,charAt(0)获取城市名称拼音的首拼字母,转换为大写,去重赋值,A-Z排序。2个用途,1是定义子集,按首拼该字母首拼的城市,2是显示在页面右侧,点击页面滚动到该字母子集的位置
    4、点击城市,该城市的id 、name等数据用vuex保存到全局中去供其他组件获取到值

    上代码

    html部分

    <div class="city">
        <header>
          <input type="text" v-model="searchcity" class="input-clear" placeholder="城市/拼音">
           <div class="over" v-if="searchaction">
            <ul>
              <li class="cityte" v-for="(item,index) in searcharr" :key="index" @click="choosecity(item.name,item.id)">{{item.name}}</li>
            </ul>
          </div>
        </header>
        <div class="mui-content">
          <div class="hot-city">
            <p>当前城市:{{this.$store.state.locatecityname}}</p>
            <p style="padding:1rem 0 0 0;">热门城市</p>
            <div class="hot-list">
              <div class="item-box fl" @click="choosecity(item.name,item.id)" v-for="(item,index) in hotcity" :key="index">{{item.name}}</div>
            </div>
          </div>
          <div class="city-main">
            <div class="city-list">
              <ul>
              	<li v-for="(item,index) in citymain" :key="index" class="cityli" :id="item.top">
              		<p class="cityle">{{item.top}}</p>
              		<ul>
                    <li v-for="(itemx,index) in item.citylist" :key="index" @click="choosecity(itemx.name,itemx.id)" class="cityte">{{itemx.name}}</li>
              		</ul>
              	</li>
              </ul>
            </div>
            <div class="city-letter">
            	<ul>
            		<li v-for="(item,index) in letter" :key="index" @click="lettercity($event)">{{item}}</li>
            	</ul>
            </div>
            <div class="showletter" v-if='showx'>{{showletter}}</div>
          </div>
        </div>
      </div>
    

    js部分

    import axios from 'axios'
    	export default {
          name:'city',
    	  data() {
    			return {
            datalist:[],
            letter:[],  //城市首拼列表
            hotcity:[],  //热门城市列表
            citymain:[],  //首拼+该首拼下城市列表
            showx:false,
            showletter:'',
            searchcity:[],  //输入框输入的文字
            searcharr:[],   //输入查找的城市匹配结果数组
            searchaction:false   //搜索城市结果列表块元素
    			}
    		},
    		
        mounted () {
          axios.get('../../static/city.json').then(response => {
            const citydata = response.data.cities;
            this.datalist = response.data.cities;
            let cityhead = []; //首拼字母集合
            let newcityhead = [];
    
            for(let i = 0;i < citydata.length;i++){
              let letteritem = citydata[i].pinyin.charAt(0).toUpperCase();  //获取城市拼音的首字母
              cityhead.push(letteritem);
    
              let ishot = citydata[i];
              if(citydata[i].isHot){
                this.hotcity.push(ishot);
              }
            }
            console.log(this.hotcity)
               
            cityhead = cityhead.sort(function compareFunction(item1,item2) {   //字母按中文顺序排序
              return item1.localeCompare(item2);
            });
            console.log(cityhead);  //字母数组,按中文顺序排,但未去重
    
            let headarr = [];
            for(let i = 0; i <cityhead.length;i++){   //去重
              if(!headarr.includes(cityhead[i])){
                headarr.push(cityhead[i]);
              }
            } 
            console.log(headarr);
            this.letter = headarr;  //完成去重并赋值
    
            for(let i = 0;i < headarr.length;i++){
              let cityitem = new Object();  //自定义对象,城市列表下子集(包括首字母、该字母首拼的城市集合)
              cityitem.top = headarr[i];   //首字母
              cityitem.citylist = [];   //该字母首拼的城市集合
                 
              for(let j = 0;j < citydata.length;j++){
                if(headarr[i].toLowerCase() === citydata[j].pinyin.charAt(0)){
                  let citya = new Object();
                  citya.name = citydata[j].name;
                  citya.id = citydata[j].cityId;
                  cityitem.citylist.push(citya);
                }
              }
              this.citymain.push(cityitem);   
            }
              
          }).catch(error => {
              console.log(error)
              this.errored = true
            }).finally(() => this.loading = false)
          },
        methods:{
          choosecity(name,id) {
            let cityid = id;
            let cityname = name;
            this.$store.commit("updatecityid",cityid)
            this.$store.commit("updatecityname",cityname)
            this.searchaction = false;
          },
          lettercity:function($event){
            let citym = document.getElementsByClassName("city-main")[0];
            let text = $event.currentTarget.innerText;
            let item = document.getElementById(text);
            this.showx = true;
            this.showletter = text;
            let that = this;
            setTimeout(function(){
              that.showx = false;
            },2000);
            citym.scrollTo(0,item.offsetTop - 350);
          }
        },
        watch:{
          searchcity:function(){
            let searchcities = [];
            if(this.searchcity != ""){
              this.searchaction = true;
              for(let i = 0;i < this.datalist.length;i++){
                let str = this.datalist[i].name;
                if(str.indexOf(this.searchcity) != -1){
                   let searchcityitem = new Object();
                   searchcityitem.id = this.datalist[i].cityId;
                   searchcityitem.name = this.datalist[i].name;
                   searchcities.push(searchcityitem);
                }  
              }
            }
            this.searcharr = searchcities;
            if(this.searchcity.length == 0){
              this.searchaction = false;  
            }else{
              this.searchaction = true;
            }
          }
        }
    	
    	}
    

    使用vuex别忘了把它注入到main.js里,我就经常忘/(ㄒoㄒ)/~~
    在这里插入图片描述

    Vuex 主要有四部分:

    state:包含了store中存储的各个状态。
    getter: 类似于 Vue 中的计算属性,根据其他 getter 或 state 计算返回值。
    mutation: 一组方法,是改变store中状态的执行者,只能是同步操作。
    action: 一组方法,其中可以包含异步操作。

    刚开始写在man.js里,但后续开发,用的越多越不方便,后来另外创了store目录存放
    在这里插入图片描述

    actions.js

    const actions = {
      ASYNC_SET_NAME({ state, commit, rootState }, payload) {
        setTimeout(() => {
          state.bName = 'asyncName'
        }, 4000)
      }
    }
    

    getter.js

    const getter = {
      doneTodos:(state,getter) => {
        return state.todos.filter(todo => todo.done)
      }
    }
    
    export default getter
    
    

    index.js

    import Vue from 'vue'
    import Vuex from 'vuex'
    import actions from './actions'
    import getter from './getter'
    import mutations from './mutations'
    import state from './state'
    
    
    Vue.use(Vuex)
    
    
    export default new Vuex.Store({
      state,
      getter,
      mutations,
      actions,
    })
    
    

    mutations.js

    const mutations = {
      updatecityname(state,arg){
        state.locatecityname = arg
      },
      updatecityid(state,arg){
        state.locatecityid = arg
      },
      savetoken(state,arg){
        state.token = arg;
         sessionStorage.setItem('Author',arg);
      },
    }
    
    export default mutations
    

    state.js

    const state = {
      locatecityname:'',
      locatecityid:'',
    }
    
    export default state
    

    最后,差点忘了,mock的城市数据city.json,当时我随便搜搜就找到了,懒得搜的,直接去我git里面拿吧
    https://github.com/czzxff/city

    展开全文
  • web端h5+vue.js实现城市选择页面和选择城市功能,完美流畅侧滑效果
  • 基于vue实现城市选择器,废话不多说,直接上代码: <template> <div class="contaienr"> <div class="mapData"> <div class="map_item clearfix" v-for="(item, index) in mapData" :...

    感谢收看

    基于vue实现的城市选择器,废话不多说,直接上代码:

    <template>
      <div class="contaienr">
        <el-select
          v-model="value"
          placeholder="请选择"
          style="float: left;margin:100px;"
          @change="hide()"
        >
          <el-option
            v-for="item in mapData"
            :key="item.name"
            :label="item.name"
            :value="item.name"
          >
            <div class="mapData" @click="hide()">
              <div class="map_item clearfix">
                <div class="left">
                  <label
                    ><input
                      type="checkbox"
                      name="is"
                      :value="item.name"
                      :checked="item.isCheck"
                      @click="isCheck(item)"
                    />{{ item.name }}</label
                  >
                </div>
                <div class="right clearfix">
                  <label v-for="(item1, index1) in item.list" :key="index1"
                    ><input
                      type="checkbox"
                      :value="item1.code"
                      v-model="item.checkedNames"
                    />{{ item1.title }}</label
                  >
                </div>
              </div>
            </div>
          </el-option>
        </el-select>
      </div>
    </template>
    <script>
    export default {
      name: "index",
      data() {
        return {
          //城市数据
          value: "",
          mapData: [
            {
              name: "北京市",
              isCheck: false,
              list: [
                {
                  title: "中国环科院站",
                  code: "BJ01",
                },
                {
                  title: "中国环科站",
                  code: "BJ02",
                },
                {
                  title: "中国环科站点",
                  code: "BJ03",
                },
                {
                  title: "中国环科站点",
                  code: "BJ04",
                },
                {
                  title: "中国环科院站",
                  code: "BJ05",
                },
                {
                  title: "中国环科站",
                  code: "BJ06",
                },
                {
                  title: "中国环科站点",
                  code: "BJ07",
                },
                {
                  title: "中国环科站点",
                  code: "BJ8",
                },
              ],
              //选中数据
              checkedNames: [],
            },
            {
              name: "天津市",
              isCheck: false,
    
              list: [
                {
                  title: "中国环科院站",
                  code: "TJ01",
                },
                {
                  title: "中国环科站",
                  code: "TJ02",
                },
                {
                  title: "中国环科站点",
                  code: "TJ03",
                },
              ],
              //选中数据
              checkedNames: [],
            },
          ],
        };
      },
      created() {},
      mounted() {},
      methods: {
        isCheck(item) {
          item.isCheck = !item.isCheck;
          if (item.isCheck) {
            for (var i = 0; i < item.list.length; i++) {
              if (item.checkedNames.indexOf(item.list[i].code) == -1) {
                item.checkedNames.push(item.list[i].code);
              }
            }
          } else {
            item.checkedNames = [];
          }
        },
        hide() {
          setTimeout(() => {
            //失去焦点
            let arr = [];
            //添加选中城市
            for (var i = 0; i < this.mapData.length; i++) {
              for (var j = 0; j < this.mapData[i].checkedNames.length; j++) {
                arr.push(this.mapData[i].checkedNames[j]);
              }
            }
            //选中城市
            console.log("所选城市=======>" + arr);
            console.log(arr);
    
            //select
            this.value = "选择站点(" + arr.length + ")";
            console.log(this.value);
          }, 100);
        },
      },
    };
    </script>
    <style>
    .mapData {
      width: 600px;
    }
    .clearfix:after {
      /*伪元素是行内元素 正常浏览器清除浮动方法*/
      content: "";
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
    }
    .clearfix {
      *zoom: 1; /*ie6清除浮动的方式 *号只有IE6-IE7执行,其他浏览器不执行*/
    }
    .left {
      float: left;
    }
    .right {
      float: right;
      width: 500px;
    }
    .right label {
      display: block;
      width: 33%;
      float: left;
    }
    .el-select-dropdown__item {
      overflow: visible;
      height: auto;
    }
    </style>

    效果图

    写的比较着急,还有一点bug 

    本来想多做介绍的,下班了,拜拜各位!

    展开全文
  • vue实现省份城市选择

    千次阅读 2019-07-03 09:53:31
    这次开发的是前端,客户没有提供城市选择的接口,省市这些数据感觉还是放在数据库后端操作较好。 数据和方法也是参考了别人博客的代码,直接贴代码 1 2 3 4 5 6 7 8 9 10...

    查看个人博客

    之前都是后端操作的,城市数据都是存在数据库的,前端选择然后去后端查的,比较简单方便。这次开发的是前端,客户没有提供城市选择的接口,省市这些数据感觉还是放在数据库后端操作较好。

    数据和方法也是参考了别人博客的代码,直接贴代码

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    <!--页面调用组件-->

    <atom-city ref="resetCountry"></atom-city>

     

       

    /*写在页面加载方法中,重置选择框中的值*/

    this.$refs.resetCountry.reset();

     

    /*写在提交方法中,从组件中获取选择的值*/

    var country = that.$refs.resetCountry.changeValueCountry()

    var province = that.$refs.resetCountry.changeValueProv()

    var city = that.$refs.resetCountry.changeValueCity()

     

    因为有多个页面需要使用,所以把选择城市的封装成atom-city组件,我这个需求是有选择国家的,如果选择的是中国才会有省份城市的选择框,否则用户自己输入省份城市,以下代码参考https://blog.csdn.net/lllo3o/article/details/72955701

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    76

    77

    78

    79

    80

    81

    82

    83

    84

    85

    86

    87

    88

    89

    90

    91

    92

    93

    94

    95

    96

    97

    98

    99

    100

    101

    102

    103

    104

    105

    106

    107

    108

    109

    110

    111

    112

    113

    114

    115

    116

    117

    118

    119

    120

    121

    122

    123

    124

    125

    126

    127

    128

    129

    130

    131

    132

    133

    134

    135

    136

    137

    138

    139

    140

    141

    142

    143

    144

    145

    146

    147

    148

    149

    150

    151

    152

    153

    154

    155

    156

    157

    158

    159

    160

    161

    162

    163

    164

    165

    166

    167

    168

    169

    170

    171

    172

    173

    174

    175

    176

    177

    178

    179

    180

    181

    182

    183

    184

    185

    186

    187

    188

    189

    190

    191

    192

    193

    194

    195

    196

    197

    198

    199

    200

    201

    202

    203

    204

    205

    206

    207

    208

    209

    210

    211

    212

    213

    214

    215

    216

    217

    218

    219

    220

    221

    222

    223

    224

    225

    226

    227

    228

    229

    230

    231

    232

    233

    234

    235

    236

    237

    238

    239

    240

    241

    242

    243

    244

    245

    246

    247

    248

    249

    250

    251

    252

    253

    254

    255

    256

    257

    258

    259

    260

    261

    262

    263

    264

    265

    266

    267

    268

    269

    270

    271

    272

    273

    274

    275

    276

    277

    278

    279

    280

    281

    282

    283

    284

    285

    286

    287

    288

    289

    290

    291

    292

    293

    294

    295

    296

    297

    298

    299

    300

    301

    302

    303

    304

    305

    306

    307

    308

    309

    310

    311

    312

    313

    314

    315

    316

    317

    318

    319

    320

    321

    322

    323

    324

    325

    326

    327

    328

    329

    330

    331

    332

    333

    334

    335

    336

    337

    338

    339

    340

    341

    342

    343

    344

    345

    346

    347

    348

    349

    350

    351

    352

    353

    354

    355

    356

    357

    358

    359

    360

    361

    362

    363

    364

    365

    366

    367

    368

    369

    370

    371

    372

    373

    374

    375

    376

    377

    378

    379

    380

    381

    382

    383

    384

    385

    386

    387

    388

    389

    390

    391

    392

    393

    394

    395

    396

    397

    398

    399

    400

    401

    402

    403

    404

    405

    406

    407

    408

    409

    410

    411

    412

    413

    414

    415

    416

    417

    418

    419

    420

    421

    422

    423

    424

    425

    426

    427

    428

    429

    430

    431

    432

    433

    434

    435

    436

    437

    438

    439

    440

    441

    442

    443

    444

    445

    446

    447

    448

    449

    450

    451

    452

    453

    454

    455

    456

    457

    458

    459

    460

    461

    462

    463

    464

    465

    466

    467

    468

    469

    470

    471

    472

    473

    474

    475

    476

    477

    478

    479

    480

    481

    482

    483

    484

    485

    486

    487

    488

    489

    490

    491

    492

    493

    494

    495

    496

    497

    498

    499

    500

    501

    502

    503

    504

    505

    506

    507

    508

    509

    510

    511

    512

    513

    514

    515

    516

    517

    518

    519

    520

    521

    522

    523

    524

    525

    526

    527

    528

    529

    530

    531

    532

    533

    534

    535

    536

    537

    538

    539

    540

    541

    542

    543

    544

    545

    546

    547

    548

    549

    550

    551

    552

    553

    554

    555

    556

    557

    558

    559

    560

    561

    562

    563

    564

    565

    566

    567

    568

    569

    570

    571

    572

    573

    574

    575

    576

    577

    578

    579

    580

    581

    582

    583

    584

    585

    586

    587

    588

    589

    590

    591

    592

    593

    594

    595

    596

    597

    598

    599

    600

    601

    602

    603

    604

    605

    606

    607

    608

    609

    610

    611

    612

    613

    614

    615

    616

    617

    618

    619

    620

    621

    622

    623

    624

    625

    626

    627

    628

    629

    630

    631

    632

    633

    634

    635

    636

    637

    638

    639

    640

    641

    642

    643

    644

    645

    646

    647

    648

    649

    650

    651

    652

    653

    654

    655

    656

    657

    658

    659

    660

    661

    662

    663

    664

    665

    666

    667

    668

    669

    670

    671

    672

    673

    674

    675

    676

    677

    678

    679

    680

    681

    682

    683

    684

    685

    686

    687

    688

    689

    690

    691

    692

    693

    694

    695

    696

    697

    698

    699

    700

    701

    702

    703

    704

    705

    706

    707

    708

    709

    710

    711

    712

    713

    714

    715

    716

    717

    718

    719

    720

    721

    722

    723

    724

    725

    726

    727

    728

    729

    730

    731

    732

    733

    734

    735

    736

    737

    738

    739

    740

    741

    742

    743

    744

    745

    746

    747

    748

    749

    750

    751

    752

    753

    754

    755

    756

    757

    758

    759

    760

    761

    762

    763

    764

    765

    766

    767

    768

    769

    770

    771

    772

    773

    774

    775

    776

    777

    778

    779

    780

    781

    782

    783

    784

    785

    786

    787

    788

    789

    790

    791

    792

    793

    794

    795

    796

    797

    798

    799

    800

    801

    802

    803

    804

    805

    806

    807

    808

    809

    810

    811

    812

    813

    814

    815

    816

    817

    818

    819

    820

    821

    822

    823

    824

    825

    826

    827

    828

    829

    830

    831

    832

    833

    834

    835

    836

    837

    838

    839

    840

    841

    842

    843

    844

    845

    846

    847

    848

    849

    850

    851

    852

    853

    854

    855

    856

    857

    858

    859

    860

    861

    862

    863

    864

    865

    866

    867

    868

    869

    870

    871

    872

    873

    874

    875

    876

    877

    878

    879

    880

    881

    882

    883

    884

    885

    886

    887

    888

    889

    890

    891

    892

    893

    894

    895

    896

    897

    898

    899

    900

    901

    902

    903

    904

    905

    906

    907

    908

    909

    910

    911

    912

    913

    914

    915

    916

    917

    918

    919

    920

    921

    922

    923

    924

    925

    926

    927

    928

    929

    930

    931

    932

    933

    934

    935

    936

    937

    938

    939

    940

    941

    942

    943

    944

    945

    946

    947

    948

    949

    950

    951

    952

    953

    954

    955

    956

    957

    958

    959

    960

    961

    962

    963

    964

    965

    966

    967

    968

    969

    970

    971

    972

    973

    974

    975

    976

    977

    978

    979

    980

    981

    982

    983

    984

    985

    986

    987

    988

    989

    990

    991

    992

    993

    994

    995

    996

    997

    998

    999

    1000

    1001

    1002

    1003

    1004

    1005

    1006

    1007

    1008

    1009

    1010

    1011

    1012

    1013

    1014

    1015

    1016

    1017

    1018

    1019

    1020

    1021

    1022

    1023

    1024

    1025

    1026

    1027

    1028

    1029

    1030

    1031

    1032

    1033

    1034

    1035

    1036

    1037

    1038

    1039

    1040

    1041

    1042

    1043

    1044

    1045

    1046

    1047

    1048

    1049

    1050

    1051

    1052

    1053

    1054

    1055

    1056

    1057

    1058

    1059

    1060

    1061

    1062

    1063

    1064

    1065

    1066

    1067

    1068

    1069

    1070

    1071

    1072

    1073

    1074

    1075

    1076

    1077

    1078

    1079

    1080

    1081

    1082

    1083

    1084

    1085

    1086

    1087

    1088

    1089

    1090

    1091

    1092

    1093

    1094

    1095

    1096

    1097

    1098

    1099

    1100

    1101

    1102

    1103

    1104

    1105

    1106

    1107

    1108

    1109

    1110

    1111

    1112

    1113

    1114

    1115

    1116

    1117

    1118

    1119

    1120

    1121

    1122

    1123

    1124

    1125

    1126

    1127

    1128

    1129

    1130

    1131

    1132

    1133

    1134

    1135

    1136

    1137

    1138

    1139

    1140

    1141

    1142

    1143

    1144

    1145

    1146

    1147

    1148

    1149

    1150

    1151

    1152

    1153

    1154

    1155

    1156

    1157

    1158

    1159

    1160

    1161

    1162

    1163

    1164

    1165

    1166

    1167

    1168

    1169

    1170

    1171

    1172

    1173

    1174

    1175

    1176

    1177

    1178

    1179

    1180

    1181

    1182

    1183

    1184

    1185

    1186

    1187

    1188

    1189

    1190

    1191

    1192

    1193

    1194

    1195

    1196

    1197

    1198

    1199

    1200

    1201

    1202

    1203

    1204

    1205

    1206

    1207

    1208

    1209

    1210

    1211

    1212

    1213

    1214

    1215

    1216

    1217

    1218

    1219

    1220

    1221

    1222

    1223

    1224

    1225

    1226

    1227

    1228

    1229

    1230

    1231

    1232

    1233

    1234

    1235

    1236

    1237

    1238

    1239

    1240

    1241

    1242

    1243

    1244

    1245

    1246

    1247

    1248

    1249

    1250

    1251

    1252

    1253

    1254

    1255

    1256

    1257

    1258

    1259

    1260

    1261

    1262

    1263

    1264

    1265

    1266

    1267

    1268

    1269

    1270

    1271

    1272

    1273

    1274

    1275

    1276

    1277

    1278

    1279

    <template>

      <div>

        <div class="form-group">

          <label>{{$t('account.countryAdd')}}</label>

          <div class="input-group height-fix-6">

              <div class="input-group-prepend"><span class="input-group-text">#</span></div>

              <select class="form-control" v-model="selectCountry" v-on:change="getCount($event)">

                  <option value="" selected>{{$t('message.pleaseEnter')}}</option>

                  <option v-for="item in countrys" :label="item.label" :value="item.value">{{item.value}}</option>

              </select>

          </div>

        </div>

        <div class="form-group">

            <div v-if="selectCountry=='中国'">

              <label>{{$t('account.provinceAdd')}}</label>

              <div class="input-group height-fix-6">

                <div class="input-group-prepend"><span class="input-group-text">#</span></div>

              <select class="form-control" v-model="selectProv" v-on:change="getProv($event)">

                <option value="" selected>{{$t('message.pleaseEnter')}}</option>

                  <option v-for="item in provs" :label="item.label" :value="item.value">{{item.value}}</option>

              </select>

            </div>

            <div v-if="selectProv!=''">

              <label>{{$t('account.cityAdd')}}</label>

              <div class="input-group height-fix-6">

                <div class="input-group-prepend"><span class="input-group-text">#</span></div>

                <select class="form-control" v-model="selectCity" v-on:change="getCity($event)">

                   <option value="" selected>{{$t('message.pleaseEnter')}}</option>

                    <option v-for="item in citys" :label="item.label" :value="item.value">{{item.value}} </option>

                </select>

              </div>

            </div>

          </div>

          <div v-if="selectCountry!='中国' && selectCountry!=''" >

              <label>{{$t('account.provinceAdd')}}</label>

              <div class="input-group height-fix-6">

                <div class="input-group-prepend"><span class="input-group-text">#</span></div>

                <input type="text" v-model="selectProv" class="form-control" :placeholder="$i18n.t('message.pleaseEnter')">

              </div>

              <label>{{$t('account.cityAdd')}}</label>

              <div class="input-group height-fix-6">

                <div class="input-group-prepend"><span class="input-group-text">#</span></div>

                <input type="text" v-model="selectCity" class="form-control" :placeholder="$i18n.t('message.pleaseEnter')">

              </div>

          </div>

     

        </div>

      </div>

    </template>

     

    <script>

    export default {

      name: 'atom-city',

      data(){

        return{

          countrys:[{label:"中国",value:"中国"},

                    {label:"日本",value:"日本"},

                    {label:"美国",value:"美国"},

                    {label:"韩国",value:"韩国"},

                    {label:"印度",value:"印度"}

          ],

          provs:[{label:"北京市",value:"北京市"},

                {label:"天津市",value:"天津市"},

                {label:"河北省",value:"河北省"},

                {label:"山西省",value:"山西省"},

                {label:"内蒙古自治区",value:"内蒙古自治区"},

                {label:"辽宁省",value:"辽宁省"},

                {label:"吉林省",value:"吉林省"},

                {label:"黑龙江省",value:"黑龙江省"},

                {label:"上海市",value:"上海市"},

                {label:"江苏省",value:"江苏省"},

                {label:"浙江省",value:"浙江省"},

                {label:"安徽省",value:"安徽省"},

                {label:"福建省",value:"福建省"},

                {label:"江西省",value:"江西省"},

                {label:"山东省",value:"山东省"},

                {label:"河南省",value:"河南省"},

                {label:"湖北省",value:"湖北省"},

                {label:"湖南省",value:"湖南省"},

                {label:"广东省",value:"广东省"},

                {label:"广西壮族自治区",value:"广西壮族自治区"},

                {label:"海南省",value:"海南省"},

                {label:"重庆市",value:"重庆市"},

                {label:"四川省",value:"四川省"},

                {label:"贵州省",value:"贵州省"},

                {label:"云南省",value:"云南省"},

                {label:"西藏自治区",value:"西藏自治区"},

                {label:"陕西省",value:"陕西省"},

                {label:"甘肃省",value:"甘肃省"},

                {label:"青海省",value:"青海省"},

                {label:"宁夏回族自治区",value:"宁夏回族自治区"},

                {label:"新疆维吾尔自治区",value:"新疆维吾尔自治区"},

                {label:"台湾省",value:"台湾省"},

                {label:"香港特别行政区",value:"香港特别行政区"},

                {label:"澳门特别行政区",value:"澳门特别行政区"}] ,

                    citys: [],

                    selectProv: '',

                    selectCity: '',

                    selectCountry:''

        }

      },

      methods: {

        /*二级联动选择地区*/

                getProv: function (prov) {

                    let tempCity=[];             

                    this.citys=[];

                    this.selectCity='';               

                    let allCity=[{

                        prov: "北京市",

                        label: "北京市"

                    }, {

                        prov: "天津市",

                        label: "天津市"

                    }, {

                        prov: "河北省",

                        label: "石家庄市"

                    }, {

                        prov: "河北省",

                        label: "唐山市"

                    }, {

                        prov: "河北省",

                        label: "秦皇岛市"

                    }, {

                        prov: "河北省",

                        label: "邯郸市"

                    }, {

                        prov: "河北省",

                        label: "邢台市"

                    }, {

                        prov: "河北省",

                        label: "保定市"

                    }, {

                        prov: "河北省",

                        label: "张家口市"

                    }, {

                        prov: "河北省",

                        label: "承德市"

                    }, {

                        prov: "河北省",

                        label: "沧州市"

                    }, {

                        prov: "河北省",

                        label: "廊坊市"

                    }, {

                        prov: "河北省",

                        label: "衡水市"

                    }, {

                        prov: "山西省",

                        label: "太原市"

                    }, {

                        prov: "山西省",

                        label: "大同市"

                    }, {

                        prov: "山西省",

                        label: "阳泉市"

                    }, {

                        prov: "山西省",

                        label: "长治市"

                    }, {

                        prov: "山西省",

                        label: "晋城市"

                    }, {

                        prov: "山西省",

                        label: "朔州市"

                    }, {

                        prov: "山西省",

                        label: "晋中市"

                    }, {

                        prov: "山西省",

                        label: "运城市"

                    }, {

                        prov: "山西省",

                        label: "忻州市"

                    }, {

                        prov: "山西省",

                        label: "临汾市"

                    }, {

                        prov: "山西省",

                        label: "吕梁市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "呼和浩特市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "包头市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "乌海市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "赤峰市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "通辽市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "鄂尔多斯市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "呼伦贝尔市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "巴彦淖尔市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "乌兰察布市"

                    }, {

                        prov: "内蒙古自治区",

                        label: "兴安盟"

                    }, {

                        prov: "内蒙古自治区",

                        label: "锡林郭勒盟"

                    }, {

                        prov: "内蒙古自治区",

                        label: "阿拉善盟"

                    }, {

                        prov: "辽宁省",

                        label: "沈阳市"

                    }, {

                        prov: "辽宁省",

                        label: "大连市"

                    }, {

                        prov: "辽宁省",

                        label: "鞍山市"

                    }, {

                        prov: "辽宁省",

                        label: "抚顺市"

                    }, {

                        prov: "辽宁省",

                        label: "本溪市"

                    }, {

                        prov: "辽宁省",

                        label: "丹东市"

                    }, {

                        prov: "辽宁省",

                        label: "锦州市"

                    }, {

                        prov: "辽宁省",

                        label: "营口市"

                    }, {

                        prov: "辽宁省",

                        label: "阜新市"

                    }, {

                        prov: "辽宁省",

                        label: "辽阳市"

                    }, {

                        prov: "辽宁省",

                        label: "盘锦市"

                    }, {

                        prov: "辽宁省",

                        label: "铁岭市"

                    }, {

                        prov: "辽宁省",

                        label: "朝阳市"

                    }, {

                        prov: "辽宁省",

                        label: "葫芦岛市"

                    }, {

                        prov: "吉林省",

                        label: "长春市"

                    }, {

                        prov: "吉林省",

                        label: "吉林市"

                    }, {

                        prov: "吉林省",

                        label: "四平市"

                    }, {

                        prov: "吉林省",

                        label: "辽源市"

                    }, {

                        prov: "吉林省",

                        label: "通化市"

                    }, {

                        prov: "吉林省",

                        label: "白山市"

                    }, {

                        prov: "吉林省",

                        label: "松原市"

                    }, {

                        prov: "吉林省",

                        label: "白城市"

                    }, {

                        prov: "吉林省",

                        label: "延边朝鲜族自治州"

                    }, {

                        prov: "黑龙江省",

                        label: "哈尔滨市"

                    }, {

                        prov: "黑龙江省",

                        label: "齐齐哈尔市"

                    }, {

                        prov: "黑龙江省",

                        label: "鸡西市"

                    }, {

                        prov: "黑龙江省",

                        label: "鹤岗市"

                    }, {

                        prov: "黑龙江省",

                        label: "双鸭山市"

                    }, {

                        prov: "黑龙江省",

                        label: "大庆市"

                    }, {

                        prov: "黑龙江省",

                        label: "伊春市"

                    }, {

                        prov: "黑龙江省",

                        label: "佳木斯市"

                    }, {

                        prov: "黑龙江省",

                        label: "七台河市"

                    }, {

                        prov: "黑龙江省",

                        label: "牡丹江市"

                    }, {

                        prov: "黑龙江省",

                        label: "黑河市"

                    }, {

                        prov: "黑龙江省",

                        label: "绥化市"

                    }, {

                        prov: "黑龙江省",

                        label: "大兴安岭地区"

                    }, {

                        prov: "上海市",

                        label: "上海市"

                    }, {

                        prov: "江苏省",

                        label: "南京市"

                    }, {

                        prov: "江苏省",

                        label: "无锡市"

                    }, {

                        prov: "江苏省",

                        label: "徐州市"

                    }, {

                        prov: "江苏省",

                        label: "常州市"

                    }, {

                        prov: "江苏省",

                        label: "苏州市"

                    }, {

                        prov: "江苏省",

                        label: "南通市"

                    }, {

                        prov: "江苏省",

                        label: "连云港市"

                    }, {

                        prov: "江苏省",

                        label: "淮安市"

                    }, {

                        prov: "江苏省",

                        label: "盐城市"

                    }, {

                        prov: "江苏省",

                        label: "扬州市"

                    }, {

                        prov: "江苏省",

                        label: "镇江市"

                    }, {

                        prov: "江苏省",

                        label: "泰州市"

                    }, {

                        prov: "江苏省",

                        label: "宿迁市"

                    }, {

                        prov: "浙江省",

                        label: "杭州市"

                    }, {

                        prov: "浙江省",

                        label: "宁波市"

                    }, {

                        prov: "浙江省",

                        label: "温州市"

                    }, {

                        prov: "浙江省",

                        label: "嘉兴市"

                    }, {

                        prov: "浙江省",

                        label: "湖州市"

                    }, {

                        prov: "浙江省",

                        label: "绍兴市"

                    }, {

                        prov: "浙江省",

                        label: "金华市"

                    }, {

                        prov: "浙江省",

                        label: "衢州市"

                    }, {

                        prov: "浙江省",

                        label: "舟山市"

                    }, {

                        prov: "浙江省",

                        label: "台州市"

                    }, {

                        prov: "浙江省",

                        label: "丽水市"

                    }, {

                        prov: "安徽省",

                        label: "合肥市"

                    }, {

                        prov: "安徽省",

                        label: "芜湖市"

                    }, {

                        prov: "安徽省",

                        label: "蚌埠市"

                    }, {

                        prov: "安徽省",

                        label: "淮南市"

                    }, {

                        prov: "安徽省",

                        label: "马鞍山市"

                    }, {

                        prov: "安徽省",

                        label: "淮北市"

                    }, {

                        prov: "安徽省",

                        label: "铜陵市"

                    }, {

                        prov: "安徽省",

                        label: "安庆市"

                    }, {

                        prov: "安徽省",

                        label: "黄山市"

                    }, {

                        prov: "安徽省",

                        label: "滁州市"

                    }, {

                        prov: "安徽省",

                        label: "阜阳市"

                    }, {

                        prov: "安徽省",

                        label: "宿州市"

                    }, {

                        prov: "安徽省",

                        label: "六安市"

                    }, {

                        prov: "安徽省",

                        label: "亳州市"

                    }, {

                        prov: "安徽省",

                        label: "池州市"

                    }, {

                        prov: "安徽省",

                        label: "宣城市"

                    }, {

                        prov: "福建省",

                        label: "福州市"

                    }, {

                        prov: "福建省",

                        label: "厦门市"

                    }, {

                        prov: "福建省",

                        label: "莆田市"

                    }, {

                        prov: "福建省",

                        label: "三明市"

                    }, {

                        prov: "福建省",

                        label: "泉州市"

                    }, {

                        prov: "福建省",

                        label: "漳州市"

                    }, {

                        prov: "福建省",

                        label: "南平市"

                    }, {

                        prov: "福建省",

                        label: "龙岩市"

                    }, {

                        prov: "福建省",

                        label: "宁德市"

                    }, {

                        prov: "江西省",

                        label: "南昌市"

                    }, {

                        prov: "江西省",

                        label: "景德镇市"

                    }, {

                        prov: "江西省",

                        label: "萍乡市"

                    }, {

                        prov: "江西省",

                        label: "九江市"

                    }, {

                        prov: "江西省",

                        label: "新余市"

                    }, {

                        prov: "江西省",

                        label: "鹰潭市"

                    }, {

                        prov: "江西省",

                        label: "赣州市"

                    }, {

                        prov: "江西省",

                        label: "吉安市"

                    }, {

                        prov: "江西省",

                        label: "宜春市"

                    }, {

                        prov: "江西省",

                        label: "抚州市"

                    }, {

                        prov: "江西省",

                        label: "上饶市"

                    }, {

                        prov: "山东省",

                        label: "济南市"

                    }, {

                        prov: "山东省",

                        label: "青岛市"

                    }, {

                        prov: "山东省",

                        label: "淄博市"

                    }, {

                        prov: "山东省",

                        label: "枣庄市"

                    }, {

                        prov: "山东省",

                        label: "东营市"

                    }, {

                        prov: "山东省",

                        label: "烟台市"

                    }, {

                        prov: "山东省",

                        label: "潍坊市"

                    }, {

                        prov: "山东省",

                        label: "济宁市"

                    }, {

                        prov: "山东省",

                        label: "泰安市"

                    }, {

                        prov: "山东省",

                        label: "威海市"

                    }, {

                        prov: "山东省",

                        label: "日照市"

                    }, {

                        prov: "山东省",

                        label: "莱芜市"

                    }, {

                        prov: "山东省",

                        label: "临沂市"

                    }, {

                        prov: "山东省",

                        label: "德州市"

                    }, {

                        prov: "山东省",

                        label: "聊城市"

                    }, {

                        prov: "山东省",

                        label: "滨州市"

                    }, {

                        prov: "山东省",

                        label: "菏泽市"

                    }, {

                        prov: "河南省",

                        label: "郑州市"

                    }, {

                        prov: "河南省",

                        label: "开封市"

                    }, {

                        prov: "河南省",

                        label: "洛阳市"

                    }, {

                        prov: "河南省",

                        label: "平顶山市"

                    }, {

                        prov: "河南省",

                        label: "安阳市"

                    }, {

                        prov: "河南省",

                        label: "鹤壁市"

                    }, {

                        prov: "河南省",

                        label: "新乡市"

                    }, {

                        prov: "河南省",

                        label: "焦作市"

                    }, {

                        prov: "河南省",

                        label: "濮阳市"

                    }, {

                        prov: "河南省",

                        label: "许昌市"

                    }, {

                        prov: "河南省",

                        label: "漯河市"

                    }, {

                        prov: "河南省",

                        label: "三门峡市"

                    }, {

                        prov: "河南省",

                        label: "南阳市"

                    }, {

                        prov: "河南省",

                        label: "商丘市"

                    }, {

                        prov: "河南省",

                        label: "信阳市"

                    }, {

                        prov: "河南省",

                        label: "周口市"

                    }, {

                        prov: "河南省",

                        label: "驻马店市"

                    }, {

                        prov: "河南省",

                        label: "省直辖县级行政区划"

                    }, {

                        prov: "湖北省",

                        label: "武汉市"

                    }, {

                        prov: "湖北省",

                        label: "黄石市"

                    }, {

                        prov: "湖北省",

                        label: "十堰市"

                    }, {

                        prov: "湖北省",

                        label: "宜昌市"

                    }, {

                        prov: "湖北省",

                        label: "襄阳市"

                    }, {

                        prov: "湖北省",

                        label: "鄂州市"

                    }, {

                        prov: "湖北省",

                        label: "荆门市"

                    }, {

                        prov: "湖北省",

                        label: "孝感市"

                    }, {

                        prov: "湖北省",

                        label: "荆州市"

                    }, {

                        prov: "湖北省",

                        label: "黄冈市"

                    }, {

                        prov: "湖北省",

                        label: "咸宁市"

                    }, {

                        prov: "湖北省",

                        label: "随州市"

                    }, {

                        prov: "湖北省",

                        label: "恩施土家族苗族自治州"

                    }, {

                        prov: "湖北省",

                        label: "省直辖县级行政区划"

                    }, {

                        prov: "湖北省",

                        label: "仙桃市"

                    }, {

                        prov: "湖北省",

                        label: "潜江市"

                    }, {

                        prov: "湖北省",

                        label: "天门市"

                    }, {

                        prov: "湖北省",

                        label: "神农架林区"

                    }, {

                        prov: "湖南省",

                        label: "长沙市"

                    }, {

                        prov: "湖南省",

                        label: "株洲市"

                    }, {

                        prov: "湖南省",

                        label: "湘潭市"

                    }, {

                        prov: "湖南省",

                        label: "衡阳市"

                    }, {

                        prov: "湖南省",

                        label: "邵阳市"

                    }, {

                        prov: "湖南省",

                        label: "岳阳市"

                    }, {

                        prov: "湖南省",

                        label: "常德市"

                    }, {

                        prov: "湖南省",

                        label: "张家界市"

                    }, {

                        prov: "湖南省",

                        label: "益阳市"

                    }, {

                        prov: "湖南省",

                        label: "郴州市"

                    }, {

                        prov: "湖南省",

                        label: "永州市"

                    }, {

                        prov: "湖南省",

                        label: "怀化市"

                    }, {

                        prov: "湖南省",

                        label: "娄底市"

                    }, {

                        prov: "湖南省",

                        label: "湘西土家族苗族自治州"

                    }, {

                        prov: "广东省",

                        label: "广州市"

                    }, {

                        prov: "广东省",

                        label: "韶关市"

                    }, {

                        prov: "广东省",

                        label: "深圳市"

                    }, {

                        prov: "广东省",

                        label: "珠海市"

                    }, {

                        prov: "广东省",

                        label: "汕头市"

                    }, {

                        prov: "广东省",

                        label: "佛山市"

                    }, {

                        prov: "广东省",

                        label: "江门市"

                    }, {

                        prov: "广东省",

                        label: "湛江市"

                    }, {

                        prov: "广东省",

                        label: "茂名市"

                    }, {

                        prov: "广东省",

                        label: "肇庆市"

                    }, {

                        prov: "广东省",

                        label: "惠州市"

                    }, {

                        prov: "广东省",

                        label: "梅州市"

                    }, {

                        prov: "广东省",

                        label: "汕尾市"

                    }, {

                        prov: "广东省",

                        label: "河源市"

                    }, {

                        prov: "广东省",

                        label: "阳江市"

                    }, {

                        prov: "广东省",

                        label: "清远市"

                    }, {

                        prov: "广东省",

                        label: "东莞市"

                    }, {

                        prov: "广东省",

                        label: "中山市"

                    }, {

                        prov: "广东省",

                        label: "潮州市"

                    }, {

                        prov: "广东省",

                        label: "揭阳市"

                    }, {

                        prov: "广东省",

                        label: "云浮市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "南宁市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "柳州市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "桂林市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "梧州市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "北海市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "防城港市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "钦州市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "贵港市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "玉林市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "百色市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "贺州市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "河池市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "来宾市"

                    }, {

                        prov: "广西壮族自治区",

                        label: "崇左市"

                    }, {

                        prov: "海南省",

                        label: "海口市"

                    }, {

                        prov: "海南省",

                        label: "三亚市"

                    }, {

                        prov: "海南省",

                        label: "三沙市"

                    }, {

                        prov: "海南省",

                        label: "省直辖县级行政区划"

                    }, {

                        prov: "海南省",

                        label: "五指山市"

                    }, {

                        prov: "海南省",

                        label: "琼海市"

                    }, {

                        prov: "海南省",

                        label: "儋州市"

                    }, {

                        prov: "海南省",

                        label: "文昌市"

                    }, {

                        prov: "海南省",

                        label: "万宁市"

                    }, {

                        prov: "海南省",

                        label: "东方市"

                    }, {

                        prov: "海南省",

                        label: "定安县"

                    }, {

                        prov: "海南省",

                        label: "屯昌县"

                    }, {

                        prov: "海南省",

                        label: "澄迈县"

                    }, {

                        prov: "海南省",

                        label: "临高县"

                    }, {

                        prov: "海南省",

                        label: "白沙黎族自治县"

                    }, {

                        prov: "海南省",

                        label: "昌江黎族自治县"

                    }, {

                        prov: "海南省",

                        label: "乐东黎族自治县"

                    }, {

                        prov: "海南省",

                        label: "陵水黎族自治县"

                    }, {

                        prov: "海南省",

                        label: "保亭黎族苗族自治县"

                    }, {

                        prov: "海南省",

                        label: "琼中黎族苗族自治县"

                    }, {

                        prov: "重庆市",

                        label: "重庆市"

                    }, {

                        prov: "四川省",

                        label: "成都市"

                    }, {

                        prov: "四川省",

                        label: "自贡市"

                    }, {

                        prov: "四川省",

                        label: "攀枝花市"

                    }, {

                        prov: "四川省",

                        label: "泸州市"

                    }, {

                        prov: "四川省",

                        label: "德阳市"

                    }, {

                        prov: "四川省",

                        label: "绵阳市"

                    }, {

                        prov: "四川省",

                        label: "广元市"

                    }, {

                        prov: "四川省",

                        label: "遂宁市"

                    }, {

                        prov: "四川省",

                        label: "内江市"

                    }, {

                        prov: "四川省",

                        label: "乐山市"

                    }, {

                        prov: "四川省",

                        label: "南充市"

                    }, {

                        prov: "四川省",

                        label: "眉山市"

                    }, {

                        prov: "四川省",

                        label: "宜宾市"

                    }, {

                        prov: "四川省",

                        label: "广安市"

                    }, {

                        prov: "四川省",

                        label: "达州市"

                    }, {

                        prov: "四川省",

                        label: "雅安市"

                    }, {

                        prov: "四川省",

                        label: "巴中市"

                    }, {

                        prov: "四川省",

                        label: "资阳市"

                    }, {

                        prov: "四川省",

                        label: "阿坝藏族羌族自治州"

                    }, {

                        prov: "四川省",

                        label: "甘孜藏族自治州"

                    }, {

                        prov: "四川省",

                        label: "凉山彝族自治州"

                    }, {

                        prov: "贵州省",

                        label: "贵阳市"

                    }, {

                        prov: "贵州省",

                        label: "六盘水市"

                    }, {

                        prov: "贵州省",

                        label: "遵义市"

                    }, {

                        prov: "贵州省",

                        label: "安顺市"

                    }, {

                        prov: "贵州省",

                        label: "毕节市"

                    }, {

                        prov: "贵州省",

                        label: "铜仁市"

                    }, {

                        prov: "贵州省",

                        label: "黔西南布依族苗族自治州"

                    }, {

                        prov: "贵州省",

                        label: "黔东南苗族侗族自治州"

                    }, {

                        prov: "贵州省",

                        label: "黔南布依族苗族自治州"

                    }, {

                        prov: "云南省",

                        label: "昆明市"

                    }, {

                        prov: "云南省",

                        label: "曲靖市"

                    }, {

                        prov: "云南省",

                        label: "玉溪市"

                    }, {

                        prov: "云南省",

                        label: "保山市"

                    }, {

                        prov: "云南省",

                        label: "昭通市"

                    }, {

                        prov: "云南省",

                        label: "丽江市"

                    }, {

                        prov: "云南省",

                        label: "普洱市"

                    }, {

                        prov: "云南省",

                        label: "临沧市"

                    }, {

                        prov: "云南省",

                        label: "楚雄彝族自治州"

                    }, {

                        prov: "云南省",

                        label: "红河哈尼族彝族自治州"

                    }, {

                        prov: "云南省",

                        label: "文山壮族苗族自治州"

                    }, {

                        prov: "云南省",

                        label: "西双版纳傣族自治州"

                    }, {

                        prov: "云南省",

                        label: "大理白族自治州"

                    }, {

                        prov: "云南省",

                        label: "德宏傣族景颇族自治州"

                    }, {

                        prov: "云南省",

                        label: "怒江傈僳族自治州"

                    }, {

                        prov: "云南省",

                        label: "迪庆藏族自治州"

                    }, {

                        prov: "西藏自治区",

                        label: "拉萨市"

                    }, {

                        prov: "西藏自治区",

                        label: "昌都地区"

                    }, {

                        prov: "西藏自治区",

                        label: "山南地区"

                    }, {

                        prov: "西藏自治区",

                        label: "日喀则地区"

                    }, {

                        prov: "西藏自治区",

                        label: "那曲地区"

                    }, {

                        prov: "西藏自治区",

                        label: "阿里地区"

                    }, {

                        prov: "西藏自治区",

                        label: "林芝地区"

                    }, {

                        prov: "陕西省",

                        label: "西安市"

                    }, {

                        prov: "陕西省",

                        label: "铜川市"

                    }, {

                        prov: "陕西省",

                        label: "宝鸡市"

                    }, {

                        prov: "陕西省",

                        label: "咸阳市"

                    }, {

                        prov: "陕西省",

                        label: "渭南市"

                    }, {

                        prov: "陕西省",

                        label: "延安市"

                    }, {

                        prov: "陕西省",

                        label: "汉中市"

                    }, {

                        prov: "陕西省",

                        label: "榆林市"

                    }, {

                        prov: "陕西省",

                        label: "安康市"

                    }, {

                        prov: "陕西省",

                        label: "商洛市"

                    }, {

                        prov: "甘肃省",

                        label: "兰州市"

                    }, {

                        prov: "甘肃省",

                        label: "嘉峪关市"

                    }, {

                        prov: "甘肃省",

                        label: "金昌市"

                    }, {

                        prov: "甘肃省",

                        label: "白银市"

                    }, {

                        prov: "甘肃省",

                        label: "天水市"

                    }, {

                        prov: "甘肃省",

                        label: "武威市"

                    }, {

                        prov: "甘肃省",

                        label: "张掖市"

                    }, {

                        prov: "甘肃省",

                        label: "平凉市"

                    }, {

                        prov: "甘肃省",

                        label: "酒泉市"

                    }, {

                        prov: "甘肃省",

                        label: "庆阳市"

                    }, {

                        prov: "甘肃省",

                        label: "定西市"

                    }, {

                        prov: "甘肃省",

                        label: "陇南市"

                    }, {

                        prov: "甘肃省",

                        label: "临夏回族自治州"

                    }, {

                        prov: "甘肃省",

                        label: "甘南藏族自治州"

                    }, {

                        prov: "青海省",

                        label: "西宁市"

                    }, {

                        prov: "青海省",

                        label: "海东市"

                    }, {

                        prov: "青海省",

                        label: "海北藏族自治州"

                    }, {

                        prov: "青海省",

                        label: "黄南藏族自治州"

                    }, {

                        prov: "青海省",

                        label: "海南藏族自治州"

                    }, {

                        prov: "青海省",

                        label: "果洛藏族自治州"

                    }, {

                        prov: "青海省",

                        label: "玉树藏族自治州"

                    }, {

                        prov: "青海省",

                        label: "海西蒙古族藏族自治州"

                    }, {

                        prov: "宁夏回族自治区",

                        label: "银川市"

                    }, {

                        prov: "宁夏回族自治区",

                        label: "石嘴山市"

                    }, {

                        prov: "宁夏回族自治区",

                        label: "吴忠市"

                    }, {

                        prov: "宁夏回族自治区",

                        label: "固原市"

                    }, {

                        prov: "宁夏回族自治区",

                        label: "中卫市"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "乌鲁木齐市"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "克拉玛依市"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "吐鲁番地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "哈密地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "昌吉回族自治州"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "博尔塔拉蒙古自治州"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "巴音郭楞蒙古自治州"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "阿克苏地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "克孜勒苏柯尔克孜自治州"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "喀什地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "和田地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "伊犁哈萨克自治州"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "塔城地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "阿勒泰地区"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "自治区直辖县级行政区划"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "石河子市"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "阿拉尔市"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "图木舒克市"

                    }, {

                        prov: "新疆维吾尔自治区",

                        label: "五家渠市"

                    }, {

                        prov: "台湾省",

                        label: "台北市"

                    }, {

                        prov: "台湾省",

                        label: "高雄市"

                    }, {

                        prov: "台湾省",

                        label: "基隆市"

                    }, {

                        prov: "台湾省",

                        label: "台中市"

                    }, {

                        prov: "台湾省",

                        label: "台南市"

                    }, {

                        prov: "台湾省",

                        label: "新竹市"

                    }, {

                        prov: "台湾省",

                        label: "嘉义市"

                    }, {

                        prov: "台湾省",

                        label: "省直辖"

                    }, {

                        prov: "香港特别行政区",

                        label: "香港岛"

                    }, {

                        prov: "香港特别行政区",

                        label: "九龙"

                    }, {

                        prov: "香港特别行政区",

                        label: "新界"

                    }, {

                        prov: "澳门特别行政区",

                        label: "澳门半岛"

                    }, {

                        prov: "澳门特别行政区",

                        label: "澳门离岛"

                    }, {

                        prov: "澳门特别行政区",

                        label: "无堂区划分区域"

                    }];

                    for (var val of allCity){

                        if (this.selectProv == val.prov){

                            console.log(val);

                            tempCity.push({label: val.label, value: val.label})

                        }

                    }

                    this.citys = tempCity;

                },

                getCity: function (city) {

                    console.log(city);

                    console.log(this.selectCity)

                },

                getCount: function(country) {

                  this.selectProv='';

                  this.citys=[];

                  this.selectCity='';

                },

                reset: function() {

                  this.selectProv= '';

                  this.selectCity='';

                  this.selectCountry='';

                },

                changeValueCountry: function(event){

                    return this.selectCountry

                },

                changeValueProv: function(event){

                    return this.selectProv

                },

                changeValueCity: function(event){

                    return this.selectCity

                }

      }

    }

    </script>

     

    其他方式参考:

    vue.js 省份城市联动选择实现示例(通过vue数组过滤)

    基于vue2实现省市联动

     

    展开全文
  • Vue实现选择城市功能

    2021-01-19 20:01:11
    查看完整的代码请到 我的github地址 https://github.com/qianyinghuanmie/vue2.0-demos 一、结果展示 二、前期准备: 1.引入汉字转拼音的插件,利用NPM安装 代码指令...1、实现1的逻辑,主要是引入vue-resource,然
  • 文章目录为input框绑定v-...去父组件City.vue中父传子,把cityies传给子组件Search.vue,子组件进行接收数据 监听keyWord,由于这部分经常用到,为了节约性能,用到函数节流,先在data中增加timer:null 初步效果如下

    为input框绑定v-model双向数据绑定

    在这里插入图片描述
    去父组件City.vue中父传子,把cityies传给子组件Search.vue,子组件进行接收数据
    在这里插入图片描述
    在这里插入图片描述
    监听keyWord,由于这部分经常用到,为了节约性能,用到函数节流,先在data中增加timer:null在这里插入图片描述
    初步效果如下,可以搜索出来了,哈哈哈哈:
    在这里插入图片描述

    增加样式,引入better-scroll插件可上下滑动

    然后修改下样式,更美观些,这时输入文字或字母搜索出来了,但是搜索的内容多的时候,不能向下滑动滑动看更多,这里需要引入better-scroll插件,获取dom

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    search.vue

    <template>
      <div>
        <div class="search">
          <input
            class="search-input"
            type="text"
            placeholder="输入城市名或拼音"
            v-model="keyWord"
          />
        </div>
        <div class="search-content" ref="search">
          <ul>
            <li
              class="search-item border-bottom"
              v-for="item in list"
              :key="item.id"
            >
              {{ item.name }}
            </li>
          </ul>
        </div>
      </div>
    </template>
    
    <script>
    import BScroll from 'better-scroll'
    export default {
      name: 'CitySearch',
      props: {
        cities: Object
      },
      data () {
        return {
          keyWord: '',
          list: [],
          timer: null
        }
      },
      // 监听keyword
      // 这里用到函数节流,因为这里用的频率比较高,节约性能
      watch: {
        keyWord () {
          if (this.timer) {
            clearTimeout(this.timer)
          }
          this.timer = setTimeout(() => {
            const result = []
            // 循环从父组件接收cities里面的内容
            for (let i in this.cities) {
              // 把cities里面的A、B、C等等键值对里面的值再给遍历一遍
              this.cities[i].forEach(value => {
                // 如果从spell,name中能搜索到这个关键词,就把这一项添加到result中
                if (
                  value.spell.indexOf(this.keyWord) > -1 ||
                  value.name.indexOf(this.keyWord) > -1
                ) {
                  result.push(value)
                }
              })
            }
            // 把result结果赋值给list数组,在上面的li中循环list数组
            this.list = result
          }, 100)
        }
      },
        // 列表解决不滑动
      updated () {
        this.scroll = new BScroll(this.$refs.search)
      }
    }
    </script>
    
    <style lang="scss" scoped>
    @import '~styles/varibles.scss';
    .search {
      background: $bgColor;
      height: 0.72rem;
      padding: 0.1rem;
      padding: 0 0.2rem;
      .search-input {
        width: 100%;
        height: 0.62rem;
        line-height: 0.62rem;
        text-align: center;
        background: #fff;
        border-radius: 0.06rem;
        color: #666;
      }
    }
    .search-content {
      overflow: hidden;
      position: absolute;
      top: 1.58rem;
      left: 0;
      right: 0;
      bottom: 0;
      background: #eee;
      z-index: 1;
      .search-item {
        line-height: 0.62rem;
        padding-left: 0.2rem;
        color: #666;
        background: #fff;
      }
    }
    </style>
    
    

    解决input框里没内容,列表还在的情况

    在这里插入图片描述
    在这里插入图片描述

    搜索结果问题

    在这里插入图片描述
    在模板里加上一个li标签
    在这里插入图片描述
    在这里插入图片描述
    需要一个判断,因为使用频率高这里用v-show,如果list列表没有数据的话,就需要显示没有找到匹配数据
    在这里插入图片描述

    输入框没值时不显示,有值才显示

    在这里插入图片描述
    整体代码如下

    <template>
      <div>
        <div class="search">
          <input
            class="search-input"
            type="text"
            placeholder="输入城市名或拼音"
            v-model="keyWord"
          />
        </div>
        <!-- 有值时才显示 -->
        <div class="search-content" ref="search" v-show="keyWord">
          <ul>
            <li
              class="search-item border-bottom"
              v-for="item in list"
              :key="item.id"
            >
              {{ item.name }}
            </li>
            <li class="search-item border-bottom" v-show="!this.list.length">没有找到匹配数据</li>
          </ul>
        </div>
      </div>
    </template>
    
    <script>
    import BScroll from 'better-scroll'
    export default {
      name: 'CitySearch',
      props: {
        cities: Object
      },
      data() {
        return {
          keyWord: '',
          list: [],
          timer: null
        }
      },
      // 监听keyword
      // 这里用到函数节流,因为这里用的频率比较高,节约性能
      watch: {
        keyWord() {
          if (this.timer) {
            clearTimeout(this.timer)
          }
          //如果input框没有输入内容,那就设置this.list为空数组
          if (!this.keyWord) {
            this.list = []
            return
          }
          this.timer = setTimeout(() => {
            const result = []
            // 循环从父组件接收cities里面的内容
            for (let i in this.cities) {
              // 把cities里面的A、B、C等等键值对里面的值再给遍历一遍
              this.cities[i].forEach(value => {
                // 如果从spell,name中能搜索到这个关键词,就把这一项添加到result中
                if (
                  value.spell.indexOf(this.keyWord) > -1 ||
                  value.name.indexOf(this.keyWord) > -1
                ) {
                  result.push(value)
                }
              })
            }
            // 把result结果赋值给list数组,在上面的li中循环list数组
            this.list = result
          }, 100)
        }
      },
      // 列表解决不滑动
      updated() {
        this.scroll = new BScroll(this.$refs.search)
      }
    }
    </script>
    
    <style lang="scss" scoped>
    @import '~styles/varibles.scss';
    .search {
      background: $bgColor;
      height: 0.72rem;
      padding: 0.1rem;
      padding: 0 0.2rem;
      .search-input {
        width: 100%;
        height: 0.62rem;
        line-height: 0.62rem;
        text-align: center;
        background: #fff;
        border-radius: 0.06rem;
        color: #666;
      }
    }
    .search-content {
      overflow: hidden;
      position: absolute;
      top: 1.58rem;
      left: 0;
      right: 0;
      bottom: 0;
      background: #eee;
      z-index: 1;
      .search-item {
        line-height: 0.62rem;
        padding-left: 0.2rem;
        color: #666;
        background: #fff;
      }
    }
    </style>
    
    

    优化代码,计算属性,尽量不要在模板里有过多的逻辑

    在这里插入图片描述

    <template>
      <div>
        <div class="search">
          <input
            class="search-input"
            type="text"
            placeholder="输入城市名或拼音"
            v-model="keyWord"
          />
        </div>
        <!-- 有值时才显示 -->
        <div class="search-content" ref="search" v-show="keyWord">
          <ul>
            <li
              class="search-item border-bottom"
              v-for="item in list"
              :key="item.id"
            >
              {{ item.name }}
            </li>
            <li class="search-item border-bottom" v-show="hasNoData">没有找到匹配数据</li>
          </ul>
        </div>
      </div>
    </template>
    
    <script>
    import BScroll from 'better-scroll'
    export default {
      name: 'CitySearch',
      props: {
        cities: Object
      },
      data () {
        return {
          keyWord: '',
          list: [],
          timer: null
        }
      },
      computed: {
        hasNoData () {
          return !this.list.length
        }
    
      },
      // 监听keyword
      // 这里用到函数节流,因为这里用的频率比较高,节约性能
      watch: {
        keyWord () {
          if (this.timer) {
            clearTimeout(this.timer)
          }
          // 如果input框没有输入内容,那就设置this.list为空数组
          if (!this.keyWord) {
            this.list = []
            return
          }
          this.timer = setTimeout(() => {
            const result = []
            // 循环从父组件接收cities里面的内容
            for (let i in this.cities) {
              // 把cities里面的A、B、C等等键值对里面的值再给遍历一遍
              this.cities[i].forEach(value => {
                // 如果从spell,name中能搜索到这个关键词,就把这一项添加到result中
                if (
                  value.spell.indexOf(this.keyWord) > -1 ||
                  value.name.indexOf(this.keyWord) > -1
                ) {
                  result.push(value)
                }
              })
            }
            // 把result结果赋值给list数组,在上面的li中循环list数组
            this.list = result
          }, 100)
        }
      },
      // 列表解决不滑动
      updated () {
        this.scroll = new BScroll(this.$refs.search)
      }
    }
    </script>
    
    <style lang="scss" scoped>
    @import '~styles/varibles.scss';
    .search {
      background: $bgColor;
      height: 0.72rem;
      padding: 0.1rem;
      padding: 0 0.2rem;
      .search-input {
        width: 100%;
        height: 0.62rem;
        line-height: 0.62rem;
        text-align: center;
        background: #fff;
        border-radius: 0.06rem;
        color: #666;
      }
    }
    .search-content {
      overflow: hidden;
      position: absolute;
      top: 1.58rem;
      left: 0;
      right: 0;
      bottom: 0;
      background: #eee;
      z-index: 1;
      .search-item {
        line-height: 0.62rem;
        padding-left: 0.2rem;
        color: #666;
        background: #fff;
      }
    }
    </style>
    
    
    
    展开全文
  • 主要为大家详细介绍了vue基于mint-ui实现城市选择三级联动,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • vue适用于pc端的城市选择组件(按城市首字母排序)
  • 主要介绍了vue+iview/elementUi实现城市多选,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
  • vue实现城市列表选择

    千次阅读 2018-07-16 11:08:00
    城市选择 <div class="iconfont back-icon"> export default { } @import '~styles/varibles.styl' ; @import '~styles/mixins.styl' ; .header overflow: hidden height $...
  • 本篇文章主要介绍了vue省市区三联动下拉选择组件的相关知识。具有很好的参考价值。下面跟着小编一起来看下吧
  • 主要为大家详细介绍了vue实现全选、反选功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • 主要为大家详细介绍了vue实现手机端省市区区域选择,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • Vue实实现现选选择择城城市市功功能能 这篇文章主要介绍了Vue实现选择城市功能,非常不错具有参考借鉴价值需要的朋友可以参考下 查看完整的 码请到 我的github地址 /qianyinghuanmie/vue2.0-demos 一一结果果展展示示...
  • 实现具备 省市区 三级联动选择功能的城市选择框。element-ui 中有相关组件,但该组件将三者统一在同一个 select 下拉选择框,使得数据双向绑定时还需要切分数据。故考虑根据实际开发情况封装该通用的联动下拉选择...
  • 本篇,我们来实现城市选择页面的列表布局。 首先创建一个分支 city-list, pull 下来,在新分支上写代码。 好啦。打开编辑器,在city/components 中创建组件List.vue 初始化一下,List.vue 代码 如下。 &lt...
  • 本文探讨一下在vue中的实现级联选择器,自己在项目中碰到过以下两种情况的后端数据,查阅资料后也证实了这两种数据的合理性: 预览地址 github地址 1 后端处理数据逻辑 这种情况是比较推荐的,大量的数据运算放在后...
  • 主要功能点:定位、城市选择实现效果 一、初始准备 这里采用 高德地图 JS API去实现上述两项功能,使用高德地图 JS API 开发地图应用需要先注册账号并申请Key,...
  • 用了element UI的select选择器 。 换成普通select也差不多。 数据没写南海诸岛,没写默认全国。 HTML: <!--联动选择地区--> 选择地区:> placeholder=请选择省份 v-on:change=getProv($event)> <el...
  • 文章内容在这哦,点击即可访问
  • 估计也是因为不难所以网上才没具体教程的吧效果图.png准备一串Json的数据json数据就是对象格式和数组格式互相嵌套,在这里大家可以下载我这个(其实我也是下载别人的),本教程也是用这个来实现的链接: ...
  • 支持不限城市,不限地区(这个东西的实现..真心死磕了挺久) – 左右两边数据的同步 地区一次性多选,若是选择了所有地区会自动转为不限地区 数据迁移箭头的判断..选中数据才会有对应的按钮可以点击 已选位置的数据...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,785
精华内容 2,314
关键字:

vue实现城市选择

vue 订阅