一.效果如下图
介绍:如图我们选择一个开始时间和结束时间,同时要设置,选择了开始时间,结束时间就不能选择开始时间之前,同理选择结束时间~~,代码
const disabledDate = time => {
return time < searchForm.value.start
}
const disabledDateStart = time => {
if (searchForm.value.end) {
return time > searchForm.value.end
}
}
二.如果你采用上图方法,返回的的时间是一个标准的时间格式,如果你多格式没要求可以忽略,接下来我们将时间格式化下
if (searchParams.start) { // 有值才转换
let date = new Date(searchParams.start)
searchParams.start =
date.getFullYear() +
"-" +
(date.getMonth() + 1) +
"-" +
date.getDate() +
" 00:00:00"
} // 转化成这种格式 2024-2-6 00:00:00
//介绍 时分秒
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
//console.log("当前时间:" + hours + ":" + minutes + ":" + seconds);
Update--
三.获取当前的时间,并转换格式为中国标准时间(解决只有一个时间选择器禁止选择之前的时间)
const result = ref(null)//全局
result = new Date() // 事件函数中,获取当前时间
-------------------------------------子组件
const props = defineProps(["result"]) //接受传值
const disabledDateStart = time => {
// 适用于一个时间选择器,选择当前之后的时间
return time < props.result
}