iview render Datepicker 起止时间限制

{
    title: '开始时间',
    key: 'planDateFrom',
    minWidth: 120,
    sortable: true,
    align: 'center',
    render: (h, params) => {
        return h('DatePicker', {
            props: {
                value: params.row.planDateFrom,
                type: 'datetime',
                format:"yyyy-MM-dd HH:mm:ss",
                editable: false,
                transfer: true,
                options: {
                    disabledDate: (date) => {
                        if (params.row.planDateTo) {
                            return date && date.valueOf() > new Date(params.row.planDateTo).valueOf();
                        };
                        if (!params.row.planDateFrom) {
                            return false;
                        };
                    }
                }
            },
            style: {
                width: '100%'
            },
            on: {
                'on-change': (e) => {
                    if (e) {
                        params.row.planDateFrom = e;
                        this.tableData[params.index] = params.row;
                    } else {
                        params.row.planDateFrom = '';   // 必须有各种判断,否则清空时无法解除之前的禁用
                        this.tableData[params.index] = params.row;
                    };
                }
            }
        });
    }
},
{
    title: '结束时间',
    key: 'planDateTo',
    minWidth: 120,
    sortable: true,
    align: 'center',
    render: (h, params) => {
        return h('DatePicker', {
            props: {
                value: params.row.planDateTo,
                type: 'datetime',
                format:"yyyy-MM-dd HH:mm:ss",
                editable: false,
                transfer: true,
                options: {
                    disabledDate: (date) => {
                        if (params.row.planDateFrom) {
                            return date && date.valueOf() < new Date(params.row.planDateFrom).valueOf();
                        }
                        if (!params.row.planDateTo) { // 不存在时,取消禁用
                            return false;
                        };
                    }
                }
            },
            style: {
                width: '100%'
            },
            on: {
                'on-change': (e) => {
                    if (e) {
                        params.row.planDateTo = e;
                        this.tableData[params.index] = params.row;
                    } else {
                        params.row.planDateTo = '';
                        this.tableData[params.index] = params.row;
                    };
                }
            }
        });
    }
},

  

转载于:https://www.cnblogs.com/web-zqk/p/10776680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值