el-date-picker组件的picker-options常规属性设置

这篇具有很好参考价值的文章主要介绍了el-date-picker组件的picker-options常规属性设置。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

el-date-picker组件的picker-options常规属性设置,Vue.js,vue.js,前端,javascript

查询已发生的配置项 

// 日期选择器快捷键配置(一般过去时)
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 };
            }
        },
    ]
},

el-date-picker组件的picker-options常规属性设置,Vue.js,vue.js,前端,javascript文章来源地址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模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包