npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

element-china-area-selector

v2.0.3

Published

Element UI 中国城市级联 省市二级 省市区三级

Downloads

24

Readme

element-china-area-selector

npm npm

Element 中国省市区级联

示例

安装

npm install --save element-china-area-selector

使用

main.js 文件中引入插件并注册

import ElementChinaAreaSelector from 'element-china-area-selector'
Vue.use(ElementChinaAreaSelector)

可选参数

| 参数名 | 默认值 | 类型 | 是否必填 | 说明 | | ---------------- | ------ | ------- | -------- | -------------------------------------------------------------------------------- | | province-code | null | Number | 是 | 省份编码 | | city-code | null | Number | 否 | 城市编码 | | region-code | null | Number | 否 | 区县编码 | | show-city | true | Boolean | 否 | 是否显示城市下拉 | | show-region | false | Boolean | 否 | 是否显示区县下拉 | | area-label | '' | String | 否 | el-form-item 文字标签 | | area-prop | '' | String | 否 | el-form-item prop 属性 | | disabled | false | Boolean | 否 | 是否全部不可选 | | provinceDisabled | false | Boolean | 否 | 是否省份不可选 | | cityDisabled | false | Boolean | 否 | 是否城市不可选 | | regionDisabled | false | Boolean | 否 | 是否区县不可选 | | options | null | Object | 否 | 更多配置 |

事件

| 事件名 | 说明 | | ---------------- | ------------------ | | areaSelectChange | 返回选中项城市信息 |

返回对象

| 属性名 | 说明 | | ------------ | -------- | | provinceCode | 省份编码 | | provinceName | 省份名 | | cityCode | 市编码 | | cityName | 市名 | | regionCode | 区县编码 | | regionName | 区县名 |

案例

注意省市区初始化无值时应传入 null

<template>
  <div style="margin: 20px auto; width: 50%;">
    <h3>使用示例</h3>
    <el-form size="small">
      <ElementChinaAreaSelector
        area-label="所属省份:"
        :province-code="formData.provinceCode"
        :show-city="false"
        @areaSelectChange="changeArea"
      />
      <ElementChinaAreaSelector
        area-label="所属省市:"
        :province-code="formData.provinceCode"
        :city-code="formData.cityCode"
        @areaSelectChange="changeArea"
      />
      <ElementChinaAreaSelector
        area-label="所属省市区"
        :show-region="true"
        :province-code="formData.provinceCode"
        :city-code="formData.cityCode"
        :region-code="formData.regionCode"
        @areaSelectChange="changeArea"
      />
      <ElementChinaAreaSelector
        area-label="所属省市区"
        :show-region="true"
        :province-disabled="true"
        :city-disabled="true"
        :province-code="formData.provinceCode"
        :city-code="formData.cityCode"
        :region-code="formData.regionCode"
        @areaSelectChange="changeArea"
      />
    </el-form>
    <h3>表单验证</h3>
    <el-form
      ref="form1"
      size="small"
      :model="form1Data"
      :inline="true"
      :rules="formDataRules1"
    >
      <ElementChinaAreaSelector
        area-label="所属省市:"
        area-prop="cityCode"
        :options="options"
        :province-code="form1Data.provinceCode"
        :city-code="form1Data.cityCode2"
        @areaSelectChange="changeArea1"
      />
      <el-form-item>
        <el-button type="primary" @click="subForm1">提交</el-button>
        <el-button @click="clearForm1">清空</el-button>
      </el-form-item>
    </el-form>
    <el-form
      ref="form2"
      size="small"
      :model="form2Data"
      :inline="true"
      :rules="formDataRules2"
    >
      <ElementChinaAreaSelector
        area-label="所属省市区"
        area-prop="regionCode"
        :options="options"
        :show-region="true"
        :province-code="form2Data.provinceCode"
        :city-code="form2Data.cityCode"
        :region-code="form2Data.regionCode2"
        @areaSelectChange="changeArea2"
      />
      <el-form-item>
        <el-button type="primary" @click="subForm2">提交</el-button>
      </el-form-item>
    </el-form>
    <h3>插槽拓展</h3>
    <el-form size="small">
      <ElementChinaAreaSelector
        area-label="所在地址:"
        :province-code="formData.provinceCode"
        :city-code="formData.cityCode"
        @areaSelectChange="changeArea"
      >
        <template slot="more">
          <div style="display: inline-block;">
            <el-form-item prop="address">
              <el-input placeholder="请输入详细地址" />
            </el-form-item>
          </div>
        </template>
      </ElementChinaAreaSelector>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: 'App',
    data() {
      return {
        options: {
          size: 'mini',
        },
        formData: {
          provinceCode: 110000,
          cityCode: 110100,
          regionCode: 110105,
        },
        // 验证省市
        form1Data: {
          provinceCode: 110000,
          cityCode: null,
        },
        formDataRules1: {
          cityCode: [
            {
              required: true,
              message: '请选择城市',
              trigger: 'change',
            },
          ],
        },
        // 验证省市区
        form2Data: {
          provinceCode: 110000,
          cityCode: 110100,
          regionCode: null,
        },
        formDataRules2: {
          regionCode: [
            {
              required: true,
              message: '请选择区县',
              trigger: 'change',
            },
          ],
        },
      }
    },
    methods: {
      changeArea(areaObj) {
        console.warn('-> ChangeArea', areaObj)
      },
      changeArea1(areaObj) {
        this.form1Data.provinceCode = areaObj.provinceCode
        this.form1Data.cityCode = areaObj.cityCode
        this.form1Data.regionCode = areaObj.regionCode
      },
      changeArea2(areaObj) {
        this.form2Data.provinceCode = areaObj.provinceCode
        this.form2Data.cityCode = areaObj.cityCode
        this.form2Data.regionCode = areaObj.regionCode
      },
      subForm1() {
        this.$refs.form1.validate((res) => {
          if (res) {
            console.log('验证通过')
          }
        })
      },
      clearForm1() {
        this.form1Data.cityCode = null
        this.$refs.form1.clearValidate()
      },
      subForm2() {
        this.$refs.form2.validate((res) => {
          if (res) {
            console.log('验证通过')
          }
        })
      },
    },
  }
</script>