/*! 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:'
A three-level linkage selection of provinces and cities, usually used in conjunction with Popup component.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Area } from 'vant';\n\nconst app = createApp();\napp.use(Area);\n
\nTo initialize Area
component, area-list
property is required.
<van-area title="Title" :area-list="areaList" />\n
\nAn 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:
\nexport 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
\nVant 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
\nimport { areaList } from '@vant/area-data';\n\nexport default {\n setup() {\n return { areaList };\n },\n};\n
\nBind the currently selected area code via v-model
.
<van-area v-model="value" title="Title" :area-list="areaList" />\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const value = ref('330302');\n return { value };\n },\n};\n
\ncolumns-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" />\n
\ncolumns-placeholder
property is used to config placeholder of columns.
<van-area\n title="Title"\n :area-list="areaList"\n :columns-placeholder="['Choose', 'Choose', 'Choose']"\n/>\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
v-model | \nthe code of selected area | \nstring | \n- | \n
title | \nToolbar title | \nstring | \n- | \n
confirm-button-text | \nText of confirm button | \nstring | \nConfirm | \n
cancel-button-text | \nText of cancel button | \nstring | \nCancel | \n
area-list | \nArea list data | \nobject | \n- | \n
columns-placeholder | \nPlaceholder of columns | \nstring[] | \n[] | \n
loading | \nWhether to show loading prompt | \nboolean | \nfalse | \n
readonly | \nWhether to be readonly | \nboolean | \nfalse | \n
option-height | \nOption height, supports px vw vh rem unit, default px | \nnumber | string | \n44 | \n
columns-num | \nLevel of picker | \nnumber | string | \n3 | \n
visible-option-num | \nCount of visible columns | \nnumber | string | \n6 | \n
swipe-duration | \nDuration of the momentum animation, unit ms | \nnumber | string | \n1000 | \n
Event | \nDescription | \nArguments | \n
---|---|---|
confirm | \nEmitted when the confirm button is clicked | \n{ selectedValues, selectedOptions, selectedIndexes } | \n
cancel | \nEmitted when the cancel button is clicked | \n{ selectedValues, selectedOptions, selectedIndexes } | \n
change | \nEmitted when current option is changed | \n{ selectedValues, selectedOptions, selectedIndexes, columnIndex } | \n
Name | \nDescription | \nSlotProps | \n
---|---|---|
toolbar 3.1.2 | \nCustom toolbar content | \n- | \n
title | \nCustom title | \n- | \n
confirm 3.1.2 | \nCustom confirm button text | \n- | \n
cancel 3.1.2 | \nCustom cancel button text | \n- | \n
columns-top | \nCustom content above columns | \n- | \n
columns-bottom | \nCustom content below columns | \n- | \n
Use ref to get Area instance and call instance methods.
\nName | \nDescription | \nAttribute | \nReturn value | \n
---|---|---|---|
confirm | \nStop scrolling and emit confirm event | \n- | \n- | \n
getSelectedOptions | \nGet current selected options | \n- | \nPickerOption[] | \n
The component exports the following type definitions:
\nimport type { AreaProps, AreaList, AreaInstance, AreaColumnOption } from 'vant';\n
\nAreaInstance
is the type of component instance:
import { ref } from 'vue';\nimport type { AreaInstance } from 'vant';\n\nconst areaRef = ref<AreaInstance>();\n\nareaRef.value?.confirm();\n
\n