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

TimePicker \u65F6\u95F4\u9009\u62E9

\n

\u4ECB\u7ECD

\n

\u65F6\u95F4\u9009\u62E9\u5668\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 { TimePicker } from 'vant';\n\nconst app = createApp();\napp.use(TimePicker);\n
\n

\u4EE3\u7801\u6F14\u793A

\n

\u57FA\u7840\u7528\u6CD5

\n

\u901A\u8FC7 v-model \u7ED1\u5B9A\u5F53\u524D\u9009\u4E2D\u7684\u65F6\u95F4\u3002

\n
<van-time-picker v-model="currentTime" title="\u9009\u62E9\u65F6\u95F4" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentTime = ref(['12', '00']);\n    return { currentTime };\n  },\n};\n
\n

\u9009\u9879\u7C7B\u578B

\n

\u901A\u8FC7 columns-type \u5C5E\u6027\u53EF\u4EE5\u63A7\u5236\u9009\u9879\u7684\u7C7B\u578B\uFF0C\u652F\u6301\u4EE5\u4EFB\u610F\u987A\u5E8F\u5BF9 hour\u3001minute \u548C second \u8FDB\u884C\u6392\u5217\u7EC4\u5408\u3002

\n

\u6BD4\u5982\uFF1A

\n\n
<van-time-picker\n  v-model="currentTime"\n  title="\u9009\u62E9\u65F6\u95F4"\n  :columns-type="columnsType"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentTime = ref(['12', '00', '00']);\n    const columnsType = ['hour', 'minute', 'second'];\n    return {\n      currentTime,\n      columnsType,\n    };\n  },\n};\n
\n

\u65F6\u95F4\u8303\u56F4

\n

\u4F60\u53EF\u4EE5\u4F7F\u7528 min-hour \u548C max-hour \u7B49\u5C5E\u6027\u6765\u9650\u5236\u5C0F\u65F6\uFF08hour\uFF09\u8303\u56F4\u3001\u5206\u949F\uFF08minute\uFF09\u8303\u56F4\u548C\u79D2\uFF08second\uFF09\u8303\u56F4\u3002

\n

\u6BD4\u5982\u4EE5\u4E0B\u793A\u4F8B\uFF0C\u7528\u6237\u53EF\u4EE5\u9009\u62E9\u7684\u5C0F\u65F6\u662F 10 ~ 20 \uFF0C\u5206\u949F\u662F 30 ~ 40\u3002

\n
<van-time-picker\n  v-model="currentTime"\n  title="\u9009\u62E9\u65F6\u95F4"\n  :min-hour="10"\n  :max-hour="20"\n  :min-minute="30"\n  :max-minute="40"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentTime = ref(['12', '35']);\n    return { currentTime };\n  },\n};\n
\n

\u6574\u4F53\u65F6\u95F4\u8303\u56F4

\n

\u4F60\u53EF\u4EE5\u4F7F\u7528 min-time \u548C max-time \u5C5E\u6027\u6765\u9650\u5236\u6574\u4F53\u65F6\u95F4\u8303\u56F4\uFF0C\u7EA6\u5B9A\u683C\u5F0F 10:00:00\u3002

\n\n

\u6BD4\u5982\u4EE5\u4E0B\u793A\u4F8B\uFF0C\u7528\u6237\u53EF\u4EE5\u9009\u62E9\u4ECE 09:40:10 \u5230 20:20:50 \u7684\u4EFB\u610F\u65F6\u95F4\u3002

\n
<van-time-picker\n  v-model="currentTime"\n  title="\u9009\u62E9\u65F6\u95F4"\n  :columns-type="['hour', 'minute', 'second']"\n  min-time="09:40:10"\n  max-time="20:20:50"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentTime = ref(['12', '00', '00']);\n    return { currentTime };\n  },\n};\n
\n

\u683C\u5F0F\u5316\u9009\u9879

\n

\u901A\u8FC7\u4F20\u5165 formatter \u51FD\u6570\uFF0C\u53EF\u4EE5\u5BF9\u9009\u9879\u7684\u6587\u5B57\u8FDB\u884C\u683C\u5F0F\u5316\u3002

\n
<van-time-picker\n  v-model="currentTime"\n  title="\u9009\u62E9\u65F6\u95F4"\n  :formatter="formatter"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentTime = ref(['12', '00']);\n    const formatter = (type, option) => {\n      if (type === 'hour') {\n        option.text += '\u65F6';\n      }\n      if (type === 'minute') {\n        option.text += '\u5206';\n      }\n      return option;\n    };\n\n    return {\n      formatter,\n      currentTime,\n    };\n  },\n};\n
\n

\u8FC7\u6EE4\u9009\u9879

\n

\u901A\u8FC7\u4F20\u5165 filter \u51FD\u6570\uFF0C\u53EF\u4EE5\u5BF9\u9009\u9879\u6570\u7EC4\u8FDB\u884C\u8FC7\u6EE4\uFF0C\u5254\u9664\u4E0D\u9700\u8981\u7684\u65F6\u95F4\uFF0C\u5B9E\u73B0\u81EA\u5B9A\u4E49\u65F6\u95F4\u95F4\u9694\u3002

\n
<van-time-picker v-model="currentTime" title="\u9009\u62E9\u65F6\u95F4" :filter="filter" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentTime = ref(['12', '00']);\n    const filter = (type, options) => {\n      if (type === 'minute') {\n        return options.filter((option) => Number(option.value) % 10 === 0);\n      }\n      return options;\n    };\n\n    return {\n      filter,\n      currentTime,\n    };\n  },\n};\n
\n

\u9AD8\u7EA7\u7528\u6CD5

\n

filter \u51FD\u6570\u7684\u7B2C\u4E09\u4E2A\u53C2\u6570\u80FD\u83B7\u53D6\u5230\u5F53\u524D\u9009\u62E9\u7684\u65F6\u95F4\uFF0C\u8FD9\u5728\u4F7F\u7528\u975E\u53D7\u63A7\u6A21\u5F0F\u65F6\uFF0C\u53EF\u4EE5\u66F4\u7075\u6D3B\u5730\u8FC7\u6EE4\u6389\u4E0D\u9700\u8981\u7684\u65F6\u95F4\u3002

\n
<van-time-picker title="\u9009\u62E9\u65F6\u95F4" :filter="filter" />\n
\n
export default {\n  setup() {\n    const filter = (type, options, values) => {\n      const hour = +values[0];\n\n      if (type === 'hour') {\n        return options.filter(\n          (option) => Number(option.value) >= 8 && Number(option.value) <= 18,\n        );\n      }\n\n      if (type === 'minute') {\n        options = options.filter((option) => Number(option.value) % 10 === 0);\n\n        if (hour === 8) {\n          return options.filter((option) => Number(option.value) >= 40);\n        }\n\n        if (hour === 18) {\n          return options.filter((option) => Number(option.value) <= 20);\n        }\n      }\n\n      return options;\n    };\n\n    return {\n      filter,\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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\u7684\u65F6\u95F4string[]-
columns-type\u9009\u9879\u7C7B\u578B\uFF0C\u7531 hour\u3001minute \u548C second \u7EC4\u6210\u7684\u6570\u7EC4string[][\'hour\', \'minute\']
min-hour\u53EF\u9009\u7684\u6700\u5C0F\u5C0F\u65F6number | string0
max-hour\u53EF\u9009\u7684\u6700\u5927\u5C0F\u65F6number | string23
min-minute\u53EF\u9009\u7684\u6700\u5C0F\u5206\u949Fnumber | string0
max-minute\u53EF\u9009\u7684\u6700\u5927\u5206\u949Fnumber | string59
min-second\u53EF\u9009\u7684\u6700\u5C0F\u79D2\u6570number | string0
max-second\u53EF\u9009\u7684\u6700\u5927\u79D2\u6570number | string59
min-time v4.5.0\u53EF\u9009\u7684\u6700\u5C0F\u65F6\u95F4\uFF0C\u683C\u5F0F\u53C2\u8003 07:40:00\uFF0C\u4F7F\u7528\u65F6 min-hour min-minute min-second \u4E0D\u4F1A\u751F\u6548string-
max-time v4.5.0\u53EF\u9009\u7684\u6700\u5927\u65F6\u95F4\uFF0C\u683C\u5F0F\u53C2\u8003 10:20:00\uFF0C\u4F7F\u7528\u65F6 max-hour max-minute max-second \u4E0D\u4F1A\u751F\u6548string-
title\u9876\u90E8\u680F\u6807\u9898string\'\'
confirm-button-text\u786E\u8BA4\u6309\u94AE\u6587\u5B57string\u786E\u8BA4
cancel-button-text\u53D6\u6D88\u6309\u94AE\u6587\u5B57string\u53D6\u6D88
show-toolbar\u662F\u5426\u663E\u793A\u9876\u90E8\u680Fbooleantrue
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
filter\u9009\u9879\u8FC7\u6EE4\u51FD\u6570(type: string, options: PickerOption[], values: string[]) => PickerOption[]-
formatter\u9009\u9879\u683C\u5F0F\u5316\u51FD\u6570(type: string, option: PickerOption) => PickerOption-
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
\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\u9879\u6539\u53D8\u65F6\u89E6\u53D1{ 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\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

\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--
getSelectedTime\u83B7\u53D6\u5F53\u524D\u9009\u4E2D\u7684\u65F6\u95F4-string[]
\n

\u7C7B\u578B\u5B9A\u4E49

\n

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

\n
import type { TimePickerProps, TimePickerColumnType } from 'vant';\n
\n

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

\n
import { ref } from 'vue';\nimport type { TimePickerInstance } from 'vant';\n\nconst timePickerRef = ref<TimePickerInstance>();\n\ntimePickerRef.value?.confirm();\n
\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,e))}}}]);