页面加载时,react-materialize
中是否有任何选项可将今天的日期设置为默认日期?
代码在下面给出
import React,{Component} from 'react';
import { Row, Col, Input, Collapsible, CollapsibleItem } from 'react-materialize';
class MetricsReport extends Component {
constructor(props) {
super(props)
this.state = {
metricsParams: {fromDate: "", toDate: ""}
}
this.handleChangeFromDate = this.handleChangeFromDate.bind(this);
this.handleChangeToDate = this.handleChangeToDate.bind(this);
}
handleChangeFromDate(event) {
let metricsParams = {...this.state.metricsParams}
metricsParams.fromDate = event.timeStamp;
this.setState({metricsParams});
}
handleChangeToDate(event) {
let metricsParams = {...this.state.metricsParams}
metricsParams.toDate = event.timeStamp; // use event.target.value to get human readable date
this.setState({metricsParams});
}
componentDidMount() {
}
render() {
return (
<div >
<label>{'From Date'}</label>
<Row>
<Input name='from' type='date' onChange={this.handleChangeFromDate} />
</Row>
<label>{'To Date'}</label>
<Row>
<Input name='to' type='date' onChange={this.handleChangeToDate} />
</Row>
</div>
)
}
}
export default MetricsReport;