Home > Web Front-end > JS Tutorial > Detailed explanation of the use of region selector (V-Distpicker) component

Detailed explanation of the use of region selector (V-Distpicker) component

php中世界最好的语言
Release: 2018-05-12 10:45:26
Original
6422 people have browsed it

This time I will bring you a detailed explanation of the use of the region selector (V-Distpicker) component. What are the precautions when using the region selector (V-Distpicker) component. The following is a practical case, let’s take a look together. take a look.

Installation and citation are copied directly from the official website, so I won’t go into details.

1. Installation

Use npm to install:

npm install v-distpicker --save
Copy after login

Use yarn to install

yarn add v-distpicker --save
Copy after login

2. Use

Register component

Register global component

import VDistpicker from 'v-distpicker'
Vue.component('v-distpicker', VDistpicker);
Copy after login

Register component

import VDistpicker from 'v-distpicker'
export default {
 components: { VDistpicker }
}
Copy after login

Simple use

Basic

<v-distpicker></v-distpicker>
Copy after login

Default value

<v-distpicker province="广东省" city="广州市" area="海珠区"></v-distpicker>
Copy after login

Mobile terminal

<v-distpicker type="mobile"></v-distpicker>
Copy after login

3. The following are the key points

Get the selected value

<template>
  <button @click="choose">点我选择区域</button>
  <p class="pwrap" v-if="show">
    <v-distpicker type="mobile" @province="onChangeProvince" @city="onChangeCity" @area="onChangeArea"></v-distpicker>
  </p>
</template>
Copy after login

Define several methods in the parent component where you reference v-distpicker to get the selected value.

<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
      }      
    },
}
Copy after login

4. Style

Do you feel that the pop-up style is ugly?

OK, let’s change the style

<style scoped>
  .pwrap{
    height: 400px;
    overflow-y: auto;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
  }
  .pwrap>>>.distpicker-address-wrapper{
    color: #999;
  }
  .pwrap>>>.address-header{
    position: fixed;
    bottom: 400px;
    width: 100%;
    background: #000;
    color:#fff;
  }
  .pwrap>>>.address-header ul li{
    flex-grow: 1;
    text-align: center;
  }
  .pwrap>>>.address-header .active{
    color: #fff;
    border-bottom:#666 solid 8px
  }
  .pwrap>>>.address-container .active{
    color: #000;
  }
</style>
Copy after login

OK, I’m done. . The above is just an introduction. If anyone has more experience, please feel free to comment

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

react-navigation usage summary (with code)

Common addition, deletion, modification and query operations of JS DOM elements Detailed explanation

The above is the detailed content of Detailed explanation of the use of region selector (V-Distpicker) component. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template