<el-date-picker
size="mini"
v-model="dateTime"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetimerange"
range-separator="~"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
/>
限制选择今天之前的时间,并且只能选择一天 文章来源:https://www.toymoban.com/news/detail-689216.html
data() {
return {
pickerMinDate: '',
pickerOptions: {
onPick: (pick) => {
this.pickerMinDate = pick; //获取当前选择日期
},
disabledDate: (date) => {
const timeStamp = 24 * 60 * 60 * 1000; //1天的时间戳
const { minDate, maxDate } = this.pickerMinDate;
if (date.getTime() > Date.now()) {
return true;
} else if (minDate && !maxDate) {
// 日期范围控制在365天内
const tamp = Math.abs(minDate.valueOf() - date.valueOf());
const customTimeStamp = timeStamp * 1; //自定义天数
if (tamp > customTimeStamp) {
return true;
}
}
},
},
}
}
只能选择今天往后365天文章来源地址https://www.toymoban.com/news/detail-689216.html
data() {
return {
valueDate: "",
pickDate: "", //存储日期
pickerOptions: {
onPick: (pick) => {
this.pickDate = pick; //获取当前选择日期
},
disabledDate: (date) => {
const timeStamp = 24 * 60 * 60 * 1000; //一天的时间戳
const { minDate, maxDate } = this.pickDate;
if (date.getTime() < Date.now() - timeStamp) {
//选择今天及以后的日期(如果不需要从今天开始,只需要控制范围,这个判断去掉即可)
return true;
} else if (minDate && !maxDate) {
// 日期范围控制在365天内
const tamp = Math.abs(minDate.valueOf() - date.valueOf());
const customTimeStamp = timeStamp * 365; //自定义天数
if (tamp > customTimeStamp) {
return true;
}
}
},
},
};
},
到了这里,关于el-date-picker限制选择的时间范围的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!