詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得
更新時間:2018年05月07日 14:00:32 作者:小爬蝦
這篇文章主要介紹了詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
廢話不多說,直接進入正題。
安裝,引用,這些直接從官網(wǎng)拷貝來的,就不多說了。
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="海珠區(qū)"></v-distpicker>
移動端
<v-distpicker type="mobile"></v-distpicker>
3、下面是重點
獲取選擇的值
<template> <button @click="choose">點我選擇區(qū)域</button> <div class="divwrap" v-if="show"> <v-distpicker type="mobile" @province="onChangeProvince" @city="onChangeCity" @area="onChangeArea"></v-distpicker> </div> </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> .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,我要說的完了。。以上只是拋磚引玉,誰有更多的使用心得,請不吝評論
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Vue ElementUI中el-table表格嵌套樣式問題小結
這篇文章主要介紹了Vue ElementUI中el-table表格嵌套樣式問題小結,兩個表格嵌套,當父表格有children數(shù)組時子表格才展示,對Vue ElementUI中el-table表格嵌套樣式問題感興趣的朋友跟隨小編一起看看吧2024-02-02