廢話不多說,直接進(jìn)入正題。
創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),江城網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:江城等地區(qū)。江城做網(wǎng)站價(jià)格咨詢:18980820575
安裝,引用,這些直接從官網(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í)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
當(dāng)前題目:詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得
文章源于:http://www.rwnh.cn/article18/jiesgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站設(shè)計(jì)公司、移動(dòng)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站改版、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)