template
<el-date-picker
:disabledDate="disabledDateFun"
clearable
v-model="state.searchtime"
type="daterange"
unlink-panels
range-separator="~"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="YYYY-MM-DD HH:mm:ss"
:shortcuts="shortcuts"
:default-time="defaultTime"
size="default" />
script
const state = reactive({
searchtime: "",
});
设置时间格式【00:00:00,23:59:59】
const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])
前三个月
const threeBefore = () => {
let date = new Date()
date.setMonth(date.getMonth() - 3)
var pastMonth = date.getMonth() + 1
var pastDay = date.getDate()
if (pastMonth >= 1 && pastMonth <= 9) { pastMonth = '0' + pastMonth }
if (pastDay >= 0 && pastDay <= 9) { pastDay = '0' + pastDay }
return date.getFullYear() + '-' + pastMonth + '-' + pastDay + ' 00:00:00'
}
设置默认显示时间
const defaultDate = () => {
let date = new Date()
let year = date.getFullYear().toString()
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString()
let da = date.getDate() < 10 ? '0' + date.getDate().toString() : date.getDate().toString()
let str = date.toTimeString().substring(0, 8);
let end = year + '-' + month + '-' + da + ' ' + str
let start = year + '-' + month + '-01' + ' 00:00:00'
state.searchtime = [start , end]
state.searchtime = [threeBefore(), end]
}

禁止选择三个月前的日期
const disabledDateFun = (time) => {
return time.getTime() < new Date(threeBefore()).getTime()
};

页面加载
onMounted(() => {defaultDate()});