在写vue项目利用饿了吗UI的时候el-date-picker组件需要只能选择一定的时间范围,比如说只能选择过去十天中的某一天:
要达到这样的效果
好了,直接上代码:
先上el-date-picker的代码
<el-date-picker
v-model="myDate"
type="date"
value-format="yyyy-MM-dd"
:picker-options="expireTimeOption"
placeholder="选择日期"
></el-date-picker>
最重要的就是expireTimeOption,它是在data中的
expireTimeOption: {
disabledDate(date) {
//disabledDate 文档上:设置禁用状态,参数为当前日期,要求返回 Boolean
return (
date.getTime() > Date.now() ||
date.getTime() < Date.now() - 1000 * 3600 * 24 * 10
);
}
}
这就表示只能选择今天前十天之内的时间了(大家还可以根据自己的更改,这个语法很好懂的)
本文介绍在Vue项目中使用饿了么UI的el-date-picker组件,如何设置只能选择过去十天内的日期。通过设置expireTimeOption属性,实现时间范围限制,代码示例展示具体实现方式。

1357

被折叠的 条评论
为什么被折叠?



