首頁  >  文章  >  web前端  >  關於VUE-地區選擇器(V-Distpicker)元件的使用介紹

關於VUE-地區選擇器(V-Distpicker)元件的使用介紹

不言
不言原創
2018-06-29 15:34:391865瀏覽

這篇文章主要介紹了詳解VUE-地區選擇器(V-Distpicker)元件使用心得,內容挺不錯的,現在分享給大家,也給大家做個參考。

廢話不多說,直接進入正題。

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

1、安裝

#使用npm 安裝:

##

npm install v-distpicker --save

使用yarn 安裝

yarn add v-distpicker --save

#2、使用

註冊元件


註冊全域元件

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

#註冊元件

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

簡單使用


基礎

<v-distpicker></v-distpicker>

#預設值

##

<v-distpicker province="广东省" city="广州市" area="海珠区"></v-distpicker>

行動端

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

#3、下面是重點

## 取得選擇的值

<template>
  <button @click="choose">点我选择区域</button>
  <p class="pwrap" v-if="show">
    <v-distpicker type="mobile" @province="onChangeProvince" @city="onChangeCity" @area="onChangeArea"></v-distpicker>
  </p>
</template>

在你引用v-distpicker 的父元件裡面定義幾個方法來取得選擇的值。

<script>
  import VDistpicker from &#39;v-distpicker&#39;
  export default {
    name: &#39;getAddress&#39;,
    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>
  .pwrap{
    height: 400px;
    overflow-y: auto;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
  }
  .pwrap>>>.distpicker-address-wrapper{
    color: #999;
  }
  .pwrap>>>.address-header{
    position: fixed;
    bottom: 400px;
    width: 100%;
    background: #000;
    color:#fff;
  }
  .pwrap>>>.address-header ul li{
    flex-grow: 1;
    text-align: center;
  }
  .pwrap>>>.address-header .active{
    color: #fff;
    border-bottom:#666 solid 8px
  }
  .pwrap>>>.address-container .active{
    color: #000;
  }

</style>

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

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網!


相關推薦:

vue中v-for載入本機靜態圖片方法

關於vue 虛擬dom的patch原始碼分析

VUE中如何使用Vue-resource完成互動


以上是關於VUE-地區選擇器(V-Distpicker)元件的使用介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn