<template>
<div class="block">
<span class="demonstration">快捷选项</span>
<el-date-picker
v-model="value2"
type="daterange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
>
</el-date-picker>
</div>
</template>
<script>
export default {
data() {
return {
pickerOptions: {
shortcuts: [
{
text: "今天",
value: () => {
const start = new Date();
const end = new Date();
start.setHours(0);
start.setMinutes(0);
start.setSeconds(0);
start.setMilliseconds(0);
start.setTime(start.getTime());
return [start, end - (60 * 60 * 24 - 1) * 1000];
},
},
{
text: "昨天",
value: () => {
const start = new Date();
const end = new Date();
start.setHours(0);
start.setMinutes(0);
start.setSeconds(0);
start.setMilliseconds(0);
end.setHours(23);
end.setMinutes(59);
end.setSeconds(59);
end.setMilliseconds(0);
start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
return [start, end - (60 * 60 * 24 - 1) * 1000];
},
},
{
text: "前三天",
value: () => {
const start = new Date();
const end = new Date();
start.setHours(0);
start.setMinutes(0);
start.setSeconds(0);
start.setMilliseconds(0);
end.setHours(23);
end.setMinutes(59);
end.setSeconds(59);
end.setMilliseconds(0);
start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
return [start, end - (60 * 60 * 24 - 1) * 1000];
},
},
{
text: "本周内",
value: () => {
element-ui 日期选择器快捷选择 shortcuts
于 2022-02-25 09:39:56 首次发布