100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > ant design vue中日期选择框混合时间选择器的用法

ant design vue中日期选择框混合时间选择器的用法

时间:2022-12-27 02:41:52

相关推荐

ant design vue中日期选择框混合时间选择器的用法

首先时间格式化用到moment方法,需要在页面中引入moment组件

importmomentfrom'moment'

结构代码:

<a-date-pickerstyle="width:100%":getCalendarContainer="(triggerNode) => triggerNode.parentNode"format="YYYY-MM-DD HH:mm:ss"v-decorator="['pushtime',{rules: [{ required: true, message: '请输入发布时间!' }]}]":showTime="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }":disabledDate="disabledDate":disabledDateTime="disabledDateTime"placeholder="请选择时间"@change="onChange"@ok="onOk" />

其中,showTime.defaultValue是设置的默认展示时间,disabledDate为禁用日期,disabledDataTime为禁用时间,详细属性说明可查阅官方文档

下面是方法代码:

methods: {moment,onChange (value, dateString) {console.log('Selected Time: ', value)console.log('Formatted Selected Time: ', dateString)},onOk (value) {console.log('onOk: ', value)},range (start, end) {const result = []for (let i = start; i < end; i++) {result.push(i)}return result},disabledDate (current) {// Can not select days before today and todayreturn current && current < moment().endOf('day')},disabledDateTime () {return {disabledHours: () => this.range(0, 24).splice(4, 20),disabledMinutes: () => this.range(30, 60),disabledSeconds: () => [55, 56]}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。