• element-ui日期筛选:选择日期即触发查询


    需求:日期范围选择器,当选择好一个日期范围时,立即触发查询功能

    <el-date-picker
        v-model="dateVal"
        type="daterange"
        size="small"
        format="yyyy 年 MM 月 dd 日"
        value-format="yyyy-MM-dd HH:mm:ss"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOption"
        :default-time="['00:00:00', '23:59:59']">
    </el-date-picker>

    js代码:

    <script type="text/ecmascript-6">
        import Detail from './detail'
        import API from 'api/api_list'
    
        export default {
            data() {
                return {
                    loading: false,
                    dateVal: '',
                    pickerOption: { // 自定义周期快捷选项
                        shortcuts: [{
                            text: '最近一周',
                            onClick: (picker => {
                                const end = new Date();
                                const start = new Date();
                                start.setHours(0);
                                start.setMinutes(0);
                                start.setSeconds(0);
                                end.setHours(23);
                                end.setMinutes(59);
                                end.setSeconds(59);
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                                this.searchChangeDate();
                            })
                        }, {
                            text: '最近一个月',
                            onClick: (picker => {
                                const end = new Date();
                                const start = new Date();
                                start.setHours(0);
                                start.setMinutes(0);
                                start.setSeconds(0);
                                end.setHours(23);
                                end.setMinutes(59);
                                end.setSeconds(59);
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                                this.searchChangeDate();
                            })
                        }, {
                            text: '最近三个月',
                            onClick: (picker => {
                                const end = new Date();
                                const start = new Date();
                                start.setHours(0);
                                start.setMinutes(0);
                                start.setSeconds(0);
                                end.setHours(23);
                                end.setMinutes(59);
                                end.setSeconds(59);
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                                this.searchChangeDate();
                            })
                        }, {
                            text: '最近半年',
                            onClick: (picker => {
                                const end = new Date();
                                const start = new Date();
                                start.setHours(0);
                                start.setMinutes(0);
                                start.setSeconds(0);
                                end.setHours(23);
                                end.setMinutes(59);
                                end.setSeconds(59);
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
                                picker.$emit('pick', [start, end]);
                                this.searchChangeDate();
                            })
                        }, {
                            text: '最近一年',
                            onClick: (picker => {
                                const end = new Date();
                                const start = new Date();
                                start.setHours(0);
                                start.setMinutes(0);
                                start.setSeconds(0);
                                end.setHours(23);
                                end.setMinutes(59);
                                end.setSeconds(59);
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
                                picker.$emit('pick', [start, end]);
                                this.searchChangeDate();
                            })
                        }],
                        onPick: (dateRange => {
                            if(!dateRange.maxDate) {
                                return;
                            }
                            this.dateVal = [dateRange.minDate, dateRange.maxDate];
                            this.searchChangeDate();
                        })
                    },
                }
            },
            created() {
                this._getLists();
            },
            methods: {
                // 日期筛选
                searchChangeDate() {
                    if (this.dateVal) {
    this._getLists(); } }, //获取列表信息 _getLists() { // ... } }, } </script>
  • 相关阅读:
    Linux下Tomcat启动、停止、重新启动
    Linux安装Tomcat
    CentOS7防火墙firewalld 和 CentOS6防火墙iptables的一些配置命令
    Zabbix监控报警Lack of free swap space on Zabbix server解决办法
    CentOS7 防火墙firewalld 和 CentOS6 防火墙iptables 开放zabbix-agent端口的方法
    yii2安装配置完成后,网页打开报错yiiwebRequest::cookieValidationKey must be configured with a secret key
    CentOS 7 使用unzip解压zip文件提示未找到命令的解决方法
    docker安装脚本
    hadoop常用命令
    yum常用安装包
  • 原文地址:https://www.cnblogs.com/yeqrblog/p/9984830.html
Copyright © 2020-2023  润新知