ant design vue中日期选择框混合时间选择器的用法
首先时间格式化用到moment方法,需要在页面中引入moment组件importmomentfrom'moment'结构代码:<a-date-pickerstyle="width:100%":getCalendarContainer="(triggerNode) => triggerNode...
·
首先时间格式化用到moment方法,需要在页面中引入moment组件
import moment from 'moment'
结构代码:
<a-date-picker
style="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 today
return current && current < moment().endOf('day')
},
disabledDateTime () {
return {
disabledHours: () => this.range(0, 24).splice(4, 20),
disabledMinutes: () => this.range(30, 60),
disabledSeconds: () => [55, 56]
}
}
}
更多推荐
已为社区贡献15条内容
所有评论(0)