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

@ophiuchus/area

v1.0.1

Published

### 介绍

Downloads

4

Readme

Area 省市区选择

介绍

省市区三级联动选择,通常与弹出层组件配合使用。

引入

import Vue from 'vue';
import Area from '@ophiuchus/area';

Vue.use(Area);

代码演示

基础用法

初始化省市区组件时,需要通过 area-list 属性传入省市区数据。

<sf-area title="标题" :area-list="areaList" />

areaList 格式

areaList 为对象结构,包含 province_listcity_listcounty_list 三个 key。

每项以地区码作为 key,省市区名字作为 value。地区码为 6 位数字,前两位代表省份,中间两位代表城市,后两位代表区县,以 0 补足 6 位。比如北京的地区码为 11,以 0 补足 6 位,为 110000

示例数据如下:

const areaList = {
  province_list: {
    110000: '北京市',
    120000: '天津市',
  },
  city_list: {
    110100: '北京市',
    120100: '天津市',
  },
  county_list: {
    110101: '东城区',
    110102: '西城区',
    // ....
  },
};

选中省市区

如果想选中某个省市区,需要传入一个 value 属性,绑定对应的省市区 code

<sf-area title="标题" :area-list="areaList" value="110101" />

配置显示列

可以通过 columns-num 属性配置省市区显示的列数,默认情况下会显示省市区,当你设置为 2,则只会显示省市选择。

<sf-area title="标题" :area-list="areaList" :columns-num="2" />

配置列占位提示文字

可以通过 columns-placeholder 属性配置每一列的占位提示文字。

<sf-area
  title="标题"
  :area-list="areaList"
  :columns-placeholder="['请选择', '请选择', '请选择']"
/>

API

Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 当前选中的省市区code | string | - | | title | 顶部栏标题 | string | - | | confirm-button-text | 确认按钮文字 | string | 确认 | | cancel-button-text | 取消按钮文字 | string | 取消 | | area-list | 省市区数据,格式见下方 | object | - | | columns-placeholder | 列占位提示文字 | string[] | [] | | loading | 是否显示加载状态 | boolean | false | | readonly | 是否为只读状态,只读状态下无法切换选项 | boolean | false | | item-height | 选项高度,支持 px vw vh rem 单位,默认 px | number | string | 44 | | columns-num | 显示列数,3-省市区,2-省市,1-省 | number | string | 3 | | visible-item-count | 可见的选项个数 | number | string | 6 | | swipe-duration | 快速滑动时惯性滚动的时长,单位ms | number | string | 1000 | | is-oversea-code | 根据code校验海外地址,海外地址会划分至单独的分类 | () => boolean | - |

Events

| 事件 | 说明 | 回调参数 | | ------- | ------------------ | ------------------------------------------- | | confirm | 点击右上方完成按钮 | 一个数组参数,具体格式看下方数据格式章节 | | cancel | 点击取消按钮时 | - | | change | 选项改变时触发 | Picker 实例,所有列选中值,当前列对应的索引 |

Slots

| 名称 | 说明 | | ----------------------- | ------------------ | | title | 自定义标题内容 | | columns-top | 自定义选项上方内容 | | columns-bottom | 自定义选项下方内容 |

方法

通过 ref 可以获取到 Area 实例并调用实例方法,详见组件实例方法

| 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | reset | 根据 code 重置所有选项,若不传 code,则重置到第一项 | code?: string | - |

点击完成时返回的数据格式

返回的数据整体为一个数组,数组内包含 columnsNum 个数据, 每个数据对应一列选项中被选中的数据。

code 代表被选中的地区编码, name 代表被选中的地区名称

[
  {
    code: '110000',
    name: '北京市',
  },
  {
    code: '110100',
    name: '北京市',
  },
  {
    code: '110101',
    name: '东城区',
  },
];

常见问题

在桌面端无法操作组件?

参见桌面端适配