当前位置:Gxlcms > JavaScript > 怎样使用V-Distpicker组件

怎样使用V-Distpicker组件

时间:2021-07-01 10:21:17 帮助过:413人阅读

这次给大家带来怎样使用V-Distpicker组件,使用V-Distpicker组件的注意事项有哪些,下面就是实战案例,一起来看一下。

1、安装

使用 npm 安装:

  1. npm install v-distpicker --save

使用 yarn 安装

  1. yarn add v-distpicker --save

2、使用

注册组件

注册全局组件

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

注册组件

  1. import VDistpicker from 'v-distpicker'
  2. export default {
  3. components: { VDistpicker }
  4. }

简单使用

基础

  1. <v-distpicker></v-distpicker>

默认值

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

移动端

  1. <v-distpicker type="mobile"></v-distpicker>

3、下面是重点

获取选择的值

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

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

  1. <script>
  2. import VDistpicker from 'v-distpicker'
  3. export default {
  4. name: 'getAddress',
  5. components: { VDistpicker },
  6. data() {
  7. return {
  8. show:false,
  9. }
  10. },
  11. methods: {
  12. choose(){
  13. this.show=!this.show
  14. },
  15. onChangeProvince(a){
  16. console.log(a)
  17. },
  18. onChangeCity(a){
  19. console.log(a)
  20. },
  21. onChangeArea(a){
  22. console.log(a)
  23. this.show=false
  24. }
  25. },
  26. }

4、样式

你是不是感觉弹出的样式很丑?

OK,下面来改改样式

  1. <style scoped>
  2. .pwrap{
  3. height: 400px;
  4. overflow-y: auto;
  5. position: fixed;
  6. left: 0;
  7. bottom: 0;
  8. width: 100%;
  9. }
  10. .pwrap>>>.distpicker-address-wrapper{
  11. color: #999;
  12. }
  13. .pwrap>>>.address-header{
  14. position: fixed;
  15. bottom: 400px;
  16. width: 100%;
  17. background: #000;
  18. color:#fff;
  19. }
  20. .pwrap>>>.address-header ul li{
  21. flex-grow: 1;
  22. text-align: center;
  23. }
  24. .pwrap>>>.address-header .active{
  25. color: #fff;
  26. border-bottom:#666 solid 8px
  27. }
  28. .pwrap>>>.address-container .active{
  29. color: #000;
  30. }
  31. </style>

OK,我要说的完了。。以上只是抛砖引玉,谁有更多的使用心得,请不吝评论

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

怎样操作Angular实现数据请求

如何操作node使用async 控制并发

以上就是怎样使用V-Distpicker组件的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行