詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得
廢話不多說,直接進(jì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 } }
簡單使用
基礎(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,我要說的完了。。以上只是拋磚引玉,誰有更多的使用心得,請不吝評論
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于Vue3創(chuàng)建一個(gè)簡單的倒計(jì)時(shí)組件
這篇文章主要給大家介紹了基于Vue3創(chuàng)建一個(gè)簡單的倒計(jì)時(shí)組件的代碼示例,文中通過代碼示例介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2023-11-11vue移動(dòng)端UI框架實(shí)現(xiàn)QQ側(cè)邊菜單組件
這篇文章主要介紹了vue移動(dòng)端UI框架實(shí)現(xiàn)仿qq側(cè)邊菜單組件,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-03-03Vue ElementUI中el-table表格嵌套樣式問題小結(jié)
這篇文章主要介紹了Vue ElementUI中el-table表格嵌套樣式問題小結(jié),兩個(gè)表格嵌套,當(dāng)父表格有children數(shù)組時(shí)子表格才展示,對Vue ElementUI中el-table表格嵌套樣式問題感興趣的朋友跟隨小編一起看看吧2024-02-02