react+antd中DatePicker组件(不能选中当前时间以前的时间)的代码

版权声明:复制发表请附上原创博客地址 https://blog.csdn.net/weixin_41077029/article/details/83012921

不能选中当前时间以前的时间:即不能选中此刻之前的时间,比如此刻是2018年10月11日15:18,那么2018年10月11日15:18分之前的所有时间都不能选,包含时分。 

const { DatePicker, Row } = antd;
class limitTime extends Component{
    state={
       	currentTime:null,
    }
    render(){
    	<Row>
			<DatePicker
				disabledDate={this.disabledEndDate}
				showTime={{ format: 'HH:mm' }}
				format="YYYY-MM-DD HH:mm"
				onOpenChange={this.handleEndOpenChange}
				/>
		</Row>
    }
    disabledEndDate = (endValue) => {
		let me = this;
		const startValue = this.state.currentTime;	
		if (!endValue || !startValue) {
		  return false;
		}
		return endValue.valueOf() <= startValue.valueOf();
	}
	handleEndOpenChange = (open) => {
		let me = this
		if(open){
			me.currentTime = moment();
		}
		this.setState({currentTime:moment() });
	}
    componentDidMount(){
	
	}
	componentDidUpdate(){

	}
	componentWillUnmount(){

	}
}

猜你喜欢

转载自blog.csdn.net/weixin_41077029/article/details/83012921
今日推荐