我是靠谱客的博主 沉默大神,这篇文章主要介绍详解VUE-地区选择器(V-Distpicker)组件使用心得,现在分享给大家,希望可以做个参考。

废话不多说,直接进入正题。

安装,引用,这些直接从官网拷贝来的,就不多说了。

1、安装

使用 npm 安装:

复制代码
1
npm install v-distpicker --save

使用 yarn 安装

复制代码
1
yarn add v-distpicker --save

2、使用

注册组件

注册全局组件

复制代码
1
2
import VDistpicker from 'v-distpicker' Vue.component('v-distpicker', VDistpicker);

注册组件

复制代码
1
2
3
4
import VDistpicker from 'v-distpicker' export default { components: { VDistpicker } }

简单使用

基础

复制代码
1
<v-distpicker></v-distpicker>

默认值

复制代码
1
<v-distpicker province="广东省" city="广州市" area="海珠区"></v-distpicker>

移动端

复制代码
1
<v-distpicker type="mobile"></v-distpicker>

3、下面是重点

获取选择的值

复制代码
1
2
3
4
5
6
<template> <button @click="choose">点我选择区域</button> <div class="divwrap" v-if="show"> <v-distpicker type="mobile" @province="onChangeProvince" @city="onChangeCity" @area="onChangeArea"></v-distpicker> </div> </template>

在你引用 v-distpicker 的父组件里面定义几个方法来获取选择的值。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<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,下面来改改样式

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<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,我要说的完了。。以上只是抛砖引玉,谁有更多的使用心得,请不吝评论

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是沉默大神最近收集整理的关于详解VUE-地区选择器(V-Distpicker)组件使用心得的全部内容,更多相关详解VUE-地区选择器(V-Distpicker)组件使用心得内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(420)

评论列表共有 0 条评论

立即
投稿
返回
顶部