溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得

發(fā)布時(shí)間:2020-08-20 16:14:04 來源:腳本之家 閱讀:257 作者:小爬蝦 欄目:web開發(fā)

廢話不多說,直接進(jìn)入正題。

安裝,引用,這些直接從官網(wǎng)拷貝來的,就不多說了。

1、安裝

使用 npm 安裝:

npm install v-distpicker --save

使用 yarn 安裝

yarn add v-distpicker --save

2、使用

注冊(cè)組件

注冊(cè)全局組件

import VDistpicker from 'v-distpicker'
Vue.component('v-distpicker', VDistpicker);

注冊(cè)組件

import VDistpicker from 'v-distpicker'
export default {
 components: { VDistpicker }
}

簡(jiǎn)單使用

基礎(chǔ)

<v-distpicker></v-distpicker>

默認(rèn)值

<v-distpicker province="廣東省" city="廣州市" area="海珠區(qū)"></v-distpicker>

移動(dòng)端

<v-distpicker type="mobile"></v-distpicker>

3、下面是重點(diǎn)

獲取選擇的值

<template>
  <button @click="choose">點(diǎn)我選擇區(qū)域</button>
  <div class="divwrap" v-if="show">
    <v-distpicker type="mobile" @province="onChangeProvince" @city="onChangeCity" @area="onChangeArea"></v-distpicker>
  </div>
</template>

在你引用 v-distpicker 的父組件里面定義幾個(gè)方法來獲取選擇的值。

<script>
  import VDistpicker from 'v-distpicker'
  export default {
    name: 'getAddress',
    components: { VDistpicker },
    data() {
      return {
        show:false,
      }
    },
    methods: {
      choose(){
        this.show=!this.show
      },
      onChangeProvince(a){
        console.log(a)        
      },
      onChangeCity(a){
        console.log(a)        
      },
      onChangeArea(a){
        console.log(a)  
        this.show=false
      }      
    },
}

 4、樣式

你是不是感覺彈出的樣式很丑?

OK,下面來改改樣式

<style scoped>
  .divwrap{
    height: 400px;
    overflow-y: auto;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
  }
  .divwrap>>>.distpicker-address-wrapper{
    color: #999;
  }
  .divwrap>>>.address-header{
    position: fixed;
    bottom: 400px;
    width: 100%;
    background: #000;
    color:#fff;
  }
  .divwrap>>>.address-header ul li{
    flex-grow: 1;
    text-align: center;
  }
  .divwrap>>>.address-header .active{
    color: #fff;
    border-bottom:#666 solid 8px
  }
  .divwrap>>>.address-container .active{
    color: #000;
  }

</style>

OK,我要說的完了。。以上只是拋磚引玉,誰有更多的使用心得,請(qǐng)不吝評(píng)論

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI