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

Picker \u9009\u62E9\u5668

\n

\u4ECB\u7ECD

\n

\u63D0\u4F9B\u591A\u4E2A\u9009\u9879\u96C6\u5408\u4F9B\u7528\u6237\u9009\u62E9\uFF0C\u652F\u6301\u5355\u5217\u9009\u62E9\u3001\u591A\u5217\u9009\u62E9\u548C\u7EA7\u8054\u9009\u62E9\uFF0C\u901A\u5E38\u4E0E\u5F39\u51FA\u5C42\u7EC4\u4EF6\u914D\u5408\u4F7F\u7528\u3002

\n

\u5F15\u5165

\n

\u901A\u8FC7\u4EE5\u4E0B\u65B9\u5F0F\u6765\u5168\u5C40\u6CE8\u518C\u7EC4\u4EF6\uFF0C\u66F4\u591A\u6CE8\u518C\u65B9\u5F0F\u8BF7\u53C2\u8003\u7EC4\u4EF6\u6CE8\u518C\u3002

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

\u4EE3\u7801\u6F14\u793A

\n

\u57FA\u7840\u7528\u6CD5

\n

\u9009\u9879\u914D\u7F6E

\n

Picker \u7EC4\u4EF6\u901A\u8FC7 columns \u5C5E\u6027\u914D\u7F6E\u9009\u9879\u6570\u636E\uFF0Ccolumns \u662F\u4E00\u4E2A\u5305\u542B\u5B57\u7B26\u4E32\u6216\u5BF9\u8C61\u7684\u6570\u7EC4\u3002

\n

\u9876\u90E8\u680F

\n

\u9876\u90E8\u680F\u5305\u542B\u6807\u9898\u3001\u786E\u8BA4\u6309\u94AE\u548C\u53D6\u6D88\u6309\u94AE\uFF0C\u70B9\u51FB\u786E\u8BA4\u6309\u94AE\u89E6\u53D1 confirm \u4E8B\u4EF6\uFF0C\u70B9\u51FB\u53D6\u6D88\u6309\u94AE\u89E6\u53D1 cancel \u4E8B\u4EF6\u3002

\n
<van-picker\n  title="\u6807\u9898"\n  :columns="columns"\n  @confirm="onConfirm"\n  @cancel="onCancel"\n  @change="onChange"\n/>\n
\n
import { showToast } from 'vant';\n\nexport default {\n  setup() {\n    const columns = [\n      { text: '\u676D\u5DDE', value: 'Hangzhou' },\n      { text: '\u5B81\u6CE2', value: 'Ningbo' },\n      { text: '\u6E29\u5DDE', value: 'Wenzhou' },\n      { text: '\u7ECD\u5174', value: 'Shaoxing' },\n      { text: '\u6E56\u5DDE', value: 'Huzhou' },\n    ];\n    const onConfirm = ({ selectedValues }) => {\n      showToast(`\u5F53\u524D\u503C: ${selectedValues.join(',')}`);\n    };\n    const onChange = ({ selectedValues }) => {\n      showToast(`\u5F53\u524D\u503C: ${selectedValues.join(',')}`);\n    };\n    const onCancel = () => showToast('\u53D6\u6D88');\n\n    return {\n      columns,\n      onChange,\n      onCancel,\n      onConfirm,\n    };\n  },\n};\n
\n

\u642D\u914D\u5F39\u51FA\u5C42\u4F7F\u7528

\n

\u5728\u5B9E\u9645\u573A\u666F\u4E2D\uFF0CPicker \u901A\u5E38\u4F5C\u4E3A\u7528\u4E8E\u8F85\u52A9\u8868\u5355\u586B\u5199\uFF0C\u53EF\u4EE5\u642D\u914D Popup \u548C Field \u5B9E\u73B0\u8BE5\u6548\u679C\u3002

\n
<van-field\n  v-model="fieldValue"\n  is-link\n  readonly\n  label="\u57CE\u5E02"\n  placeholder="\u9009\u62E9\u57CE\u5E02"\n  @click="showPicker = true"\n/>\n<van-popup v-model:show="showPicker" round position="bottom">\n  <van-picker\n    :columns="columns"\n    @cancel="showPicker = false"\n    @confirm="onConfirm"\n  />\n</van-popup>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const columns = [\n      { text: '\u676D\u5DDE', value: 'Hangzhou' },\n      { text: '\u5B81\u6CE2', value: 'Ningbo' },\n      { text: '\u6E29\u5DDE', value: 'Wenzhou' },\n      { text: '\u7ECD\u5174', value: 'Shaoxing' },\n      { text: '\u6E56\u5DDE', value: 'Huzhou' },\n    ];\n    const fieldValue = ref('');\n    const showPicker = ref(false);\n\n    const onConfirm = ({ selectedOptions }) => {\n      showPicker.value = false;\n      fieldValue.value = selectedOptions[0].text;\n    };\n\n    return {\n      columns,\n      onConfirm,\n      fieldValue,\n      showPicker,\n    };\n  },\n};\n
\n

\u53CC\u5411\u7ED1\u5B9A

\n

\u901A\u8FC7 v-model \u53EF\u4EE5\u7ED1\u5B9A\u5F53\u524D\u9009\u4E2D\u9879\u7684 values\uFF0C\u4FEE\u6539 v-model \u7ED1\u5B9A\u7684\u503C\u65F6\uFF0CPicker \u7684\u9009\u4E2D\u72B6\u6001\u4E5F\u4F1A\u968F\u4E4B\u6539\u53D8\u3002

\n

v-model \u7684\u503C\u662F\u4E00\u4E2A\u6570\u7EC4\uFF0C\u6570\u7EC4\u7684\u7B2C\u4E00\u4F4D\u5BF9\u5E94\u7B2C\u4E00\u5217\u9009\u4E2D\u9879\u7684 value\uFF0C\u7B2C\u4E8C\u4F4D\u5BF9\u5E94\u7B2C\u4E8C\u5217\u9009\u4E2D\u9879\u7684 value\uFF0C\u4EE5\u6B64\u7C7B\u63A8\u3002

\n
<van-picker v-model="selectedValues" title="\u6807\u9898" :columns="columns" />\n
\n
import { showToast } from 'vant';\n\nexport default {\n  setup() {\n    const columns = [\n      { text: '\u676D\u5DDE', value: 'Hangzhou' },\n      { text: '\u5B81\u6CE2', value: 'Ningbo' },\n      { text: '\u6E29\u5DDE', value: 'Wenzhou' },\n      { text: '\u7ECD\u5174', value: 'Shaoxing' },\n      { text: '\u6E56\u5DDE', value: 'Huzhou' },\n    ];\n    const selectedValues = ref(['Wenzhou']);\n\n    return {\n      columns,\n      selectedValues,\n    };\n  },\n};\n
\n

\u591A\u5217\u9009\u62E9

\n

columns \u5C5E\u6027\u53EF\u4EE5\u901A\u8FC7\u4E8C\u7EF4\u6570\u7EC4\u7684\u5F62\u5F0F\u914D\u7F6E\u591A\u5217\u9009\u62E9\u3002

\n
<van-picker title="\u6807\u9898" :columns="columns" />\n
\n
export default {\n  setup() {\n    const columns = [\n      // \u7B2C\u4E00\u5217\n      [\n        { text: '\u5468\u4E00', value: 'Monday' },\n        { text: '\u5468\u4E8C', value: 'Tuesday' },\n        { text: '\u5468\u4E09', value: 'Wednesday' },\n        { text: '\u5468\u56DB', value: 'Thursday' },\n        { text: '\u5468\u4E94', value: 'Friday' },\n      ],\n      // \u7B2C\u4E8C\u5217\n      [\n        { text: '\u4E0A\u5348', value: 'Morning' },\n        { text: '\u4E0B\u5348', value: 'Afternoon' },\n        { text: '\u665A\u4E0A', value: 'Evening' },\n      ],\n    ];\n\n    return { columns };\n  },\n};\n
\n

\u7EA7\u8054\u9009\u62E9

\n

\u4F7F\u7528 columns \u7684 children \u5B57\u6BB5\u53EF\u4EE5\u5B9E\u73B0\u9009\u9879\u7EA7\u8054\u7684\u6548\u679C\u3002\u5982\u679C\u7EA7\u8054\u5C42\u7EA7\u8F83\u591A\uFF0C\u63A8\u8350\u4F7F\u7528 Cascader \u7EA7\u8054\u9009\u9879\u7EC4\u4EF6\u3002

\n
<van-picker title="\u6807\u9898" :columns="columns" />\n
\n
export default {\n  setup() {\n    const columns = [\n      {\n        text: '\u6D59\u6C5F',\n        value: 'Zhejiang',\n        children: [\n          {\n            text: '\u676D\u5DDE',\n            value: 'Hangzhou',\n            children: [\n              { text: '\u897F\u6E56\u533A', value: 'Xihu' },\n              { text: '\u4F59\u676D\u533A', value: 'Yuhang' },\n            ],\n          },\n          {\n            text: '\u6E29\u5DDE',\n            value: 'Wenzhou',\n            children: [\n              { text: '\u9E7F\u57CE\u533A', value: 'Lucheng' },\n              { text: '\u74EF\u6D77\u533A', value: 'Ouhai' },\n            ],\n          },\n        ],\n      },\n      {\n        text: '\u798F\u5EFA',\n        value: 'Fujian',\n        children: [\n          {\n            text: '\u798F\u5DDE',\n            value: 'Fuzhou',\n            children: [\n              { text: '\u9F13\u697C\u533A', value: 'Gulou' },\n              { text: '\u53F0\u6C5F\u533A', value: 'Taijiang' },\n            ],\n          },\n          {\n            text: '\u53A6\u95E8',\n            value: 'Xiamen',\n            children: [\n              { text: '\u601D\u660E\u533A', value: 'Siming' },\n              { text: '\u6D77\u6CA7\u533A', value: 'Haicang' },\n            ],\n          },\n        ],\n      },\n    ];\n\n    return { columns };\n  },\n};\n
\n
\n

\u7EA7\u8054\u9009\u62E9\u7684\u6570\u636E\u5D4C\u5957\u6DF1\u5EA6\u9700\u8981\u4FDD\u6301\u4E00\u81F4\uFF0C\u5982\u679C\u90E8\u5206\u9009\u9879\u6CA1\u6709\u5B50\u9009\u9879\uFF0C\u53EF\u4EE5\u4F7F\u7528\u7A7A\u5B57\u7B26\u4E32\u8FDB\u884C\u5360\u4F4D\u3002

\n
\n

\u7981\u7528\u9009\u9879

\n

\u9009\u9879\u53EF\u4EE5\u4E3A\u5BF9\u8C61\u7ED3\u6784\uFF0C\u901A\u8FC7\u8BBE\u7F6E disabled \u6765\u7981\u7528\u8BE5\u9009\u9879\u3002

\n
<van-picker :columns="columns" />\n
\n
export default {\n  setup() {\n    const columns = [\n      { text: '\u676D\u5DDE', value: 'Hangzhou', disabled: true },\n      { text: '\u5B81\u6CE2', value: 'Ningbo' },\n      { text: '\u6E29\u5DDE', value: 'Wenzhou' },\n    ];\n    return { columns };\n  },\n};\n
\n

\u52A0\u8F7D\u72B6\u6001

\n

\u82E5\u9009\u62E9\u5668\u6570\u636E\u662F\u5F02\u6B65\u83B7\u53D6\u7684\uFF0C\u53EF\u4EE5\u901A\u8FC7 loading \u5C5E\u6027\u663E\u793A\u52A0\u8F7D\u63D0\u793A\u3002

\n
<van-picker :columns="columns" :loading="loading" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const columns = ref([]);\n    const loading = ref(true);\n\n    setTimeout(() => {\n      columns.value = [{ text: '\u9009\u9879', value: 'option' }];\n      loading.value = false;\n    }, 1000);\n\n    return { columns, loading };\n  },\n};\n
\n

\u81EA\u5B9A\u4E49 Columns \u7684\u7ED3\u6784

\n
<van-picker\n  :title="\u6807\u9898"\n  :columns="columns"\n  :columns-field-names="customFieldName"\n/>\n
\n
export default {\n  setup() {\n    const columns = [\n      {\n        cityName: '\u6D59\u6C5F',\n        cities: [\n          {\n            cityName: '\u676D\u5DDE',\n            cities: [{ cityName: '\u897F\u6E56\u533A' }, { cityName: '\u4F59\u676D\u533A' }],\n          },\n          {\n            cityName: '\u6E29\u5DDE',\n            cities: [{ cityName: '\u9E7F\u57CE\u533A' }, { cityName: '\u74EF\u6D77\u533A' }],\n          },\n        ],\n      },\n      {\n        cityName: '\u798F\u5EFA',\n        cities: [\n          {\n            cityName: '\u798F\u5DDE',\n            cities: [{ cityName: '\u9F13\u697C\u533A' }, { cityName: '\u53F0\u6C5F\u533A' }],\n          },\n          {\n            cityName: '\u53A6\u95E8',\n            cities: [{ cityName: '\u601D\u660E\u533A' }, { cityName: '\u6D77\u6CA7\u533A' }],\n          },\n        ],\n      },\n    ];\n\n    const customFieldName = {\n      text: 'cityName',\n      value: 'cityName',\n      children: 'cities',\n    };\n\n    return {\n      columns,\n      customFieldName,\n    };\n  },\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\n\n\n\n\n\n\n\n\n\n\n\n
\u53C2\u6570\u8BF4\u660E\u7C7B\u578B\u9ED8\u8BA4\u503C
v-model\u5F53\u524D\u9009\u4E2D\u9879\u5BF9\u5E94\u7684\u503Cnumber[] | string[]-
columns\u5BF9\u8C61\u6570\u7EC4\uFF0C\u914D\u7F6E\u6BCF\u4E00\u5217\u663E\u793A\u7684\u6570\u636EPickerOption[] | PickerOption[][][]
columns-field-names\u81EA\u5B9A\u4E49 columns \u7ED3\u6784\u4E2D\u7684\u5B57\u6BB5object{ text: \'text\', value: \'value\', children: \'children\' }
title\u9876\u90E8\u680F\u6807\u9898string-
confirm-button-text\u786E\u8BA4\u6309\u94AE\u6587\u5B57\uFF0C\u8BBE\u7F6E\u4E3A\u7A7A\u5B57\u7B26\u4E32\u53EF\u4EE5\u9690\u85CF\u6309\u94AEstring\u786E\u8BA4
cancel-button-text\u53D6\u6D88\u6309\u94AE\u6587\u5B57\uFF0C\u8BBE\u7F6E\u4E3A\u7A7A\u5B57\u7B26\u4E32\u53EF\u4EE5\u9690\u85CF\u6309\u94AEstring\u53D6\u6D88
toolbar-position\u9876\u90E8\u680F\u4F4D\u7F6E\uFF0C\u53EF\u9009\u503C\u4E3A bottomstringtop
loading\u662F\u5426\u663E\u793A\u52A0\u8F7D\u72B6\u6001booleanfalse
readonly\u662F\u5426\u4E3A\u53EA\u8BFB\u72B6\u6001\uFF0C\u53EA\u8BFB\u72B6\u6001\u4E0B\u65E0\u6CD5\u5207\u6362\u9009\u9879booleanfalse
show-toolbar\u662F\u5426\u663E\u793A\u9876\u90E8\u680Fbooleantrue
allow-html\u662F\u5426\u5141\u8BB8\u9009\u9879\u5185\u5BB9\u4E2D\u6E32\u67D3 HTMLbooleanfalse
option-height\u9009\u9879\u9AD8\u5EA6\uFF0C\u652F\u6301 px vw vh rem \u5355\u4F4D\uFF0C\u9ED8\u8BA4 pxnumber | string44
visible-option-num\u53EF\u89C1\u7684\u9009\u9879\u4E2A\u6570number | string6
swipe-duration\u5FEB\u901F\u6ED1\u52A8\u65F6\u60EF\u6027\u6EDA\u52A8\u7684\u65F6\u957F\uFF0C\u5355\u4F4D 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\n\n\n\n\n\n\n\n\n\n
\u4E8B\u4EF6\u540D\u8BF4\u660E\u56DE\u8C03\u53C2\u6570
confirm\u70B9\u51FB\u5B8C\u6210\u6309\u94AE\u65F6\u89E6\u53D1{ selectedValues, selectedOptions, selectedIndexes }
cancel\u70B9\u51FB\u53D6\u6D88\u6309\u94AE\u65F6\u89E6\u53D1{ selectedValues, selectedOptions, selectedIndexes }
change\u9009\u4E2D\u7684\u9009\u9879\u6539\u53D8\u65F6\u89E6\u53D1{ selectedValues, selectedOptions, selectedIndexes, columnIndex }
click-option\u70B9\u51FB\u9009\u9879\u65F6\u89E6\u53D1{ currentOption, selectedValues, selectedOptions, selectedIndexes, columnIndex }
scroll-into v4.2.1\u5F53\u7528\u6237\u901A\u8FC7\u70B9\u51FB\u6216\u62D6\u62FD\u8BA9\u4E00\u4E2A\u9009\u9879\u6EDA\u52A8\u5230\u4E2D\u95F4\u7684\u9009\u62E9\u533A\u57DF\u65F6\u89E6\u53D1{ currentOption, 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\n\n\n\n\n
\u540D\u79F0\u8BF4\u660E\u53C2\u6570
toolbar\u81EA\u5B9A\u4E49\u6574\u4E2A\u9876\u90E8\u680F\u7684\u5185\u5BB9-
title\u81EA\u5B9A\u4E49\u6807\u9898\u5185\u5BB9-
confirm\u81EA\u5B9A\u4E49\u786E\u8BA4\u6309\u94AE\u5185\u5BB9-
cancel\u81EA\u5B9A\u4E49\u53D6\u6D88\u6309\u94AE\u5185\u5BB9-
option\u81EA\u5B9A\u4E49\u9009\u9879\u5185\u5BB9option: PickerOption, index: number
columns-top\u81EA\u5B9A\u4E49\u9009\u9879\u4E0A\u65B9\u5185\u5BB9-
columns-bottom\u81EA\u5B9A\u4E49\u9009\u9879\u4E0B\u65B9\u5185\u5BB9-
\n

PickerOption \u6570\u636E\u7ED3\u6784

\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
\u952E\u540D\u8BF4\u660E\u7C7B\u578B
text\u9009\u9879\u6587\u5B57\u5185\u5BB9string | number
value\u9009\u9879\u5BF9\u5E94\u7684\u503Cstring | number
disabled\u662F\u5426\u7981\u7528\u9009\u9879boolean
children\u7EA7\u8054\u9009\u9879PickerOption[]
className\u9009\u9879\u989D\u5916\u7C7B\u540Dstring | Array | object
\n

\u65B9\u6CD5

\n

\u901A\u8FC7 ref \u53EF\u4EE5\u83B7\u53D6\u5230 Picker \u5B9E\u4F8B\u5E76\u8C03\u7528\u5B9E\u4F8B\u65B9\u6CD5\uFF0C\u8BE6\u89C1\u7EC4\u4EF6\u5B9E\u4F8B\u65B9\u6CD5\u3002

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u65B9\u6CD5\u540D\u8BF4\u660E\u53C2\u6570\u8FD4\u56DE\u503C
confirm\u505C\u6B62\u60EF\u6027\u6EDA\u52A8\u5E76\u89E6\u53D1 confirm \u4E8B\u4EF6--
getSelectedOptions\u83B7\u53D6\u5F53\u524D\u9009\u4E2D\u7684\u9009\u9879-(PickerOption | undefined)[]
\n

\u7C7B\u578B\u5B9A\u4E49

\n

\u7EC4\u4EF6\u5BFC\u51FA\u4EE5\u4E0B\u7C7B\u578B\u5B9A\u4E49\uFF1A

\n
import type {\n  PickerProps,\n  PickerColumn,\n  PickerOption,\n  PickerInstance,\n  PickerFieldNames,\n  PickerToolbarPosition,\n  PickerCancelEventParams,\n  PickerChangeEventParams,\n  PickerConfirmEventParams,\n} from 'vant';\n
\n

PickerInstance \u662F\u7EC4\u4EF6\u5B9E\u4F8B\u7684\u7C7B\u578B\uFF0C\u7528\u6CD5\u5982\u4E0B\uFF1A

\n
import { ref } from 'vue';\nimport type { PickerInstance } from 'vant';\n\nconst pickerRef = ref<PickerInstance>();\n\npickerRef.value?.confirm();\n
\n

\u4E3B\u9898\u5B9A\u5236

\n

\u6837\u5F0F\u53D8\u91CF

\n

\u7EC4\u4EF6\u63D0\u4F9B\u4E86\u4E0B\u5217 CSS \u53D8\u91CF\uFF0C\u53EF\u7528\u4E8E\u81EA\u5B9A\u4E49\u6837\u5F0F\uFF0C\u4F7F\u7528\u65B9\u6CD5\u8BF7\u53C2\u8003 ConfigProvider \u7EC4\u4EF6\u3002

\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\n\n
\u540D\u79F0\u9ED8\u8BA4\u503C\u63CF\u8FF0
--van-picker-backgroundvar(--van-background-2)-
--van-picker-toolbar-height44px-
--van-picker-title-font-sizevar(--van-font-size-lg)-
--van-picker-title-line-heightvar(--van-line-height-md)-
--van-picker-action-padding0 var(--van-padding-md)-
--van-picker-action-font-sizevar(--van-font-size-md)-
--van-picker-confirm-action-colorvar(--van-primary-color)-
--van-picker-cancel-action-colorvar(--van-text-color-2)-
--van-picker-option-padding0 var(--van-padding-base)-
--van-picker-option-font-sizevar(--van-font-size-lg)-
--van-picker-option-text-colorvar(--van-text-color)-
--van-picker-option-disabled-opacity0.3-
--van-picker-mask-colorlinear-gradient-
--van-picker-loading-icon-colorvar(--van-primary-color)-
--van-picker-loading-mask-colorrgba(255, 255, 255, 0.9)-
\n

\u5E38\u89C1\u95EE\u9898

\n

\u5728\u684C\u9762\u7AEF\u65E0\u6CD5\u64CD\u4F5C\u7EC4\u4EF6\uFF1F

\n

\u53C2\u89C1\u684C\u9762\u7AEF\u9002\u914D\u3002

\n
'},null,8,l))}}}]);