文章来源:https://www.toymoban.com/news/detail-575978.html
查询已发生的配置项
// 日期选择器快捷键配置(一般过去时)
pickerOptions: {
shortcuts: [
{
text: '今天',
onClick(picker) {
let start = new Date();
let end = new Date();
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '昨天',
onClick(picker) {
let start = new Date();
let end = new Date();
start.setDate(start.getDate() - 1);
end.setDate(end.getDate() - 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '迄今为止',
onClick(picker) {
let start = new Date('2000-01-01');
let end = new Date();
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
// ----------------------------------------
{
text: '近一周',
onClick(picker) {
let start = new Date();
let end = new Date();
start.setDate(start.getDate() - 6);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '近一个月',
onClick(picker) {
let start = new Date();
let end = new Date();
start.setMonth(start.getMonth() - 1);
start.setDate(start.getDate() + 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '近三个月',
onClick(picker) {
let start = new Date();
let end = new Date();
start.setMonth(start.getMonth() - 3);
start.setDate(start.getDate() + 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '近一年',
onClick(picker) {
let start = new Date();
let end = new Date();
start.setFullYear(start.getFullYear() - 1);
start.setDate(start.getDate() + 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
// ----------------------------------------
{
text: '上月',
onClick(picker) {
let lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);
let m = lastMonth.getMonth(), y = lastMonth.getFullYear();
let start = new Date(y, m, 1);
let end = new Date(y, m, new Date(y, m + 1, 0).getDate());
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '本月',
onClick(picker) {
let now = new Date(), m = now.getMonth(), y = now.getFullYear();
let start = new Date(y, m, 1);
let end = new Date(y, m, new Date(y, m + 1, 0).getDate());
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '今年',
onClick(picker) {
let start = new Date(new Date().getFullYear(), 0, 1);
let end = new Date(new Date().getFullYear(), 11, 31);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '去年',
onClick(picker) {
let start = new Date(new Date().getFullYear() - 1, 0, 1);
let end = new Date(new Date().getFullYear() - 1, 11, 31);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
]
},
文章来源地址https://www.toymoban.com/news/detail-575978.html
设置未来日期配置
// 日期选择器快捷键配置(一般将来时)
pickerOptions: {
shortcuts: [
{
text: '今天',
onClick(picker) {
let start = new Date();
let end = new Date();
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '明天',
onClick(picker) {
let start = new Date();
let end = new Date();
start.setDate(start.getDate() + 1);
end.setDate(end.getDate() + 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '从今往后',
onClick(picker) {
let start = new Date();
let end = new Date('2999-12-31');
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
// ----------------------------------------
{
text: '往后一周',
onClick(picker) {
let start = new Date();
let end = new Date();
end.setDate(start.getDate() + 6);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '往后一个月',
onClick(picker) {
let start = new Date();
let end = new Date();
end.setMonth(start.getMonth() + 1);
end.setDate(start.getDate() - 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '往后三个月',
onClick(picker) {
let start = new Date();
let end = new Date();
end.setMonth(start.getMonth() + 3);
end.setDate(start.getDate() - 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '往后一年',
onClick(picker) {
let start = new Date();
let end = new Date();
end.setDate(start.getDate() + 365);
end.setDate(start.getDate() - 1);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
// ----------------------------------------
{
text: '本月',
onClick(picker) {
let now = new Date(), m = now.getMonth(), y = now.getFullYear();
let start = new Date(y, m, 1);
let end = new Date(y, m, new Date(y, m + 1, 0).getDate());
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '下个月',
onClick(picker) {
let nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
let m = nextMonth.getMonth(), y = nextMonth.getFullYear();
let start = new Date(y, m, 1);
let end = new Date(y, m, new Date(y, m + 1, 0).getDate());
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '今年',
onClick(picker) {
let start = new Date(new Date().getFullYear(), 0, 1);
let end = new Date(new Date().getFullYear(), 11, 31);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
{
text: '明年',
onClick(picker) {
let start = new Date(new Date().getFullYear() + 1, 0, 1);
let end = new Date(new Date().getFullYear() + 1, 11, 31);
if (picker) picker.$emit('pick', [start, end]);
else return { start, end };
}
},
]
},
到了这里,关于el-date-picker组件的picker-options常规属性设置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!