首頁 > web前端 > js教程 > 主體

怎樣使用V-Distpicker元件

php中世界最好的语言
發布: 2018-05-31 10:19:46
原創
1793 人瀏覽過

這次帶給大家怎樣使用V-Distpicker元件,使用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 '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>
  .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中文網其它相關文章!

推薦閱讀:

怎麼操作Angular實作資料請求

#如何操作node使用async 控制並發

#

以上是怎樣使用V-Distpicker元件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!