Home

Awesome

<p align="center"> <img src="https://pigjian.com/images/v-distpicker.png" alt="Powered By Jiajian Chan" width="160"> </p> <p align="center">A flexible, highly available district selector for picking provinces, cities and districts of China. </p>

V - Distpicker

github-stars github-stars download-image

Documents and Demo

[English] | 简体中文

CHANGELOG

Installation

Vue 2

npm install v-distpicker@^1.3.3 --save

Vue 3

npm install v-distpicker@^2.1.0 --save

CDN

<script src="https://cdn.jsdelivr.net/npm/v-distpicker@version/dist/v-distpicker.js"></script>
<!-- or -->
<script src="https://unpkg.com/v-distpicker@version/dist/v-distpicker.js"></script>

Usage

Register component

Registe global component:

import VDistpicker from 'v-distpicker'
const app = createApp(App)
app.component('v-distpicker', VDistpicker)

Use setup-api:

<script setup>import VDistpicker from 'v-distpicker'</script>

Registe component:

import { defineComponent } from 'vue'
import VDistpicker from 'v-distpicker'

export default defineComponent({
  components: { VDistpicker },
})

How to use

Basic:

<v-distpicker></v-distpicker>

Default Value:

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

Mobile:

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

Demo:

<template>
  <v-distpicker
    :province="select.province"
    :city="select.city"
    :area="select.area"
    @selected="onSelect"
    @change="onChange"
    @province="selectProvince"
    @city="selectCity"
    @area="selectArea"
  ></v-distpicker>
</template>

<script setup>
import VDistpicker from 'v-distpicker'
let select = reactive({ province: '', city: '', area: '' })
function onSelect(data) {
  console.log(data)
}
function onChange(data) {
  console.log(data)
}
function selectProvince({ code, value }) {
  select.province = value
  console.log({ code, value })
}
function selectCity({ code, value }) {
  select.city = value
  console.log({ code, value })
}
function selectArea({ code, value }) {
  select.area = value
  console.log({ code, value })
}
</script>

Props

NameTypeDescriptionDefaultSample
provinceString/Number省级编码或名称'广东省'/440000/'440000'
cityString/Number市级编码或名称'广州市'/440100/'440100'
areaString/Number区级编码或名称'海珠区'/440105/'440105'
placeholderObject默认显示的值{province:'省',city:'市',area:'区'}
typeString区分 pc 和 mobile,默认 pc
only-provinceBoolean只显示省级选择器false
hide-areaBoolean隐藏区级false
disabledBoolean禁用false
province-disabledBoolean禁用省false
city-disabledBoolean禁用市false
area-disabledBoolean禁用区false
province-sourceObject省数据源examples/components/data
city-sourceObject市级数据源
address-sourceObject区级数据源
wrapperStringclassName'distpicker-address-wrapper'
address-headerStringclassName(mobile)'address-header'
address-containerStringclassName(mobile)'address-container'

Event

NameTypeDescriptionReturn
provinceFunction选择省时触发{code,value}
cityFunction选择市时触发{code,value}
areaFunction选择区时触发{code,value}
selectedFunction选择最后一项时触发{province:{code,value},city:{code,value},area:{code,value} }
change-provinceFunction省级改变时触发{code,value}
change-cityFunction市级改变时触发{code,value}
change-areaFunction区级改变时触发{code,value}
changeFunction省市区改变时触发{province:{code,value},city:{code,value},area:{code,value} }

Contributors

<a href="https://github.com/jcc/v-distpicker/graphs/contributors"> <img src="https://contrib.rocks/image?repo=jcc/v-distpicker" /> </a>

Thanks

License

The plugin is open-sourced software licensed under the MIT license.