詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得
廢話不多說(shuō),直接進(jìn)入正題。
安裝,引用,這些直接從官網(wǎng)拷貝來(lái)的,就不多說(shuō)了。
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è)方法來(lái)獲取選擇的值。
<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、樣式
你是不是感覺(jué)彈出的樣式很丑?
OK,下面來(lái)改改樣式
<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,我要說(shuō)的完了。。以上只是拋磚引玉,誰(shuí)有更多的使用心得,請(qǐng)不吝評(píng)論
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于Vue3創(chuàng)建一個(gè)簡(jiǎn)單的倒計(jì)時(shí)組件
這篇文章主要給大家介紹了基于Vue3創(chuàng)建一個(gè)簡(jiǎn)單的倒計(jì)時(shí)組件的代碼示例,文中通過(guò)代碼示例介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2023-11-11Vue注冊(cè)組件命名時(shí)不能用大寫(xiě)的原因淺析
這段時(shí)間一直在弄vue,當(dāng)然也遇到很多問(wèn)題,這里就來(lái)跟大家分享一些注冊(cè)自定義模板組件的心得 ,需要的朋友可以參考下2019-04-04解決vue A對(duì)象賦值給B對(duì)象,修改B屬性會(huì)影響到A的問(wèn)題
今天小編就為大家分享一篇解決vue A對(duì)象賦值給B對(duì)象,修改B屬性會(huì)影響到A的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09Vue.js實(shí)現(xiàn)的購(gòu)物車功能詳解
這篇文章主要介紹了Vue.js實(shí)現(xiàn)的購(gòu)物車功能,結(jié)合實(shí)例形式分析了vue.js購(gòu)物車的原理、數(shù)值計(jì)算及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-01-01vue移動(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表格嵌套樣式問(wèn)題小結(jié)
這篇文章主要介紹了Vue ElementUI中el-table表格嵌套樣式問(wèn)題小結(jié),兩個(gè)表格嵌套,當(dāng)父表格有children數(shù)組時(shí)子表格才展示,對(duì)Vue ElementUI中el-table表格嵌套樣式問(wèn)題感興趣的朋友跟隨小編一起看看吧2024-02-02Vue使用Vuex一步步封裝并使用store全過(guò)程
這篇文章主要介紹了Vue使用Vuex一步步封裝并使用store全過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01