import{o as t,a,y as e}from"./vue-libs.b44bc779.js";const n={class:"van-doc-markdown-body"},d=e(`

Area

Intro

A three-level linkage selection of provinces and cities, usually used in conjunction with Popup component.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { Area } from 'vant';

const app = createApp();
app.use(Area);

Usage

Basic Usage

To initialize Area component, area-list property is required.

<van-area title="Title" :area-list="areaList" />

areaList Data Structure

An object contains three properties: province_list, city_list and county_list. Each property is a simple key-value object, key is a 6-bit code of the area of which first two bits stand for the province or state, middle two bits are used as city code and the last two are district code, value is the name of the area. If the code stands for an area that has sub-areas, lower bits of it will be filled with 0.

Sample data:

export default {
  province_list: {
    110000: 'Beijing',
    330000: 'Zhejiang Province',
  },
  city_list: {
    110100: 'Beijing City',
    330100: 'Hangzhou',
  },
  county_list: {
    110101: 'Dongcheng District',
    110102: 'Xicheng District',
    // ....
  },
};

@vant/area-data

Vant officially provides a default China area data, which can be imported through @vant/area-data:

# with npm
npm i @vant/area-data

# with yarn
yarn add @vant/area-data

# with pnpm
pnpm add @vant/area-data
import { areaList } from '@vant/area-data';

export default {
  setup() {
    return { areaList };
  },
};

Initial Value

To have a selected value, simply pass the code of target area to value property.

<van-area title="Title" :area-list="areaList" value="110101" />

Columns Number

columns-num property is used to config number of columns to be displayed. This component has 3 columns corresponding to a 3 level picker by default. Set columns-num with 2, you'll have a 2 level picker.

<van-area title="Title" :area-list="areaList" :columns-num="2" />

Columns Placeholder

columns-placeholder property is used to config placeholder of columns.

<van-area
  title="Title"
  :area-list="areaList"
  :columns-placeholder="['Choose', 'Choose', 'Choose']"
/>

API

Props

AttributeDescriptionTypeDefault
valuethe code of selected areastring-
titleToolbar titlestring-
confirm-button-textText of confirm buttonstringConfirm
cancel-button-textText of cancel buttonstringCancel
area-listArea list dataobject-
columns-placeholderPlaceholder of columnsstring[][]
loadingWhether to show loading promptbooleanfalse
readonlyWhether to be readonlybooleanfalse
item-heightOption height, supports px vw vh rem unit, default pxnumber | string44
columns-numLevel of pickernumber | string3
visible-item-countCount of visible columnsnumber | string6
swipe-durationDuration of the momentum animation, unit msnumber | string1000
is-oversea-codeThe method to validate oversea code() => boolean-

Events

EventDescriptionArguments
confirmEmitted when the confirm button is clickedresult: ConfirmResult
cancelEmitted when the cancel button is clicked-
changeEmitted when current option changedcurrent: values, column: index

ConfirmResult

An array that contains selected area objects.

[
  {
    code: '330000',
    name: 'Zhejiang Province',
  },
  {
    code: '330100',
    name: 'Hangzhou',
  },
  {
    code: '330105',
    name: 'Xihu District',
  },
];

Slots

NameDescriptionSlotProps
toolbar 3.1.2Custom toolbar content-
titleCustom title-
confirm 3.1.2Custom confirm button text-
cancel 3.1.2Custom cancel button text-
columns-topCustom content above columns-
columns-bottomCustom content below columns-

Methods

Use ref to get Area instance and call instance methods.

NameDescriptionAttributeReturn value
resetReset all options by codecode?: string-

Types

The component exports the following type definitions:

import type { AreaProps, AreaList, AreaInstance, AreaColumnOption } from 'vant';

AreaInstance is the type of component instance:

import { ref } from 'vue';
import type { AreaInstance } from 'vant';

const areaRef = ref<AreaInstance>();

areaRef.value?.reset();
`,17),l=[d],h={__name:"README",setup(o,{expose:s}){return s({frontmatter:{}}),(r,p)=>(t(),a("div",n,l))}};export{h as default};