/*! For license information please see 8389.276d5df0.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["8389"],{17666:function(n,s,t){"use strict";t.r(s);var a=t("80681");let e=["innerHTML"];s.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

Area

\n

Intro

\n

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

\n

Install

\n

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

\n
import { createApp } from 'vue';\nimport { Area } from 'vant';\n\nconst app = createApp();\napp.use(Area);\n
\n

Usage

\n

Basic Usage

\n

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

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

areaList Data Structure

\n

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.

\n

Sample data:

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

China Area Data

\n

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

\n
# with npm\nnpm i @vant/area-data\n\n# with yarn\nyarn add @vant/area-data\n\n# with pnpm\npnpm add @vant/area-data\n\n# with Bun\nbun add @vant/area-data\n
\n
import { areaList } from '@vant/area-data';\n\nexport default {\n  setup() {\n    return { areaList };\n  },\n};\n
\n

Model Value

\n

Bind the currently selected area code via v-model.

\n
<van-area v-model="value" title="Title" :area-list="areaList" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const value = ref('330302');\n    return { value };\n  },\n};\n
\n

Columns Number

\n

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.

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

Columns Placeholder

\n

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

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

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
v-modelthe 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
option-heightOption height, supports px vw vh rem unit, default pxnumber | string44
columns-numLevel of pickernumber | string3
visible-option-numCount of visible columnsnumber | string6
swipe-durationDuration of the momentum animation, unit msnumber | string1000
\n

Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
EventDescriptionArguments
confirmEmitted when the confirm button is clicked{ selectedValues, selectedOptions, selectedIndexes }
cancelEmitted when the cancel button is clicked{ selectedValues, selectedOptions, selectedIndexes }
changeEmitted when current option is changed{ selectedValues, selectedOptions, selectedIndexes, columnIndex }
\n

Slots

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
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-
\n

Methods

\n

Use ref to get Area instance and call instance methods.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionAttributeReturn value
confirmStop scrolling and emit confirm event--
getSelectedOptionsGet current selected options-PickerOption[]
\n

Types

\n

The component exports the following type definitions:

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

AreaInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { AreaInstance } from 'vant';\n\nconst areaRef = ref<AreaInstance>();\n\nareaRef.value?.confirm();\n
\n
'},null,8,e))}}}]);