首先引入moment 插件
import moment from 'moment'
<span style={{ display: "inline-block", marginRight: "8px", cursor: 'pointer' }} onClick={() => {
this.setDate("day")
}}>今日</span>
<span style={{ display: "inline-block", marginRight: "8px", cursor: 'pointer' }} onClick={() => {
this.setDate("week")
}}>本周</span>
<span style={{ display: "inline-block", marginRight: "8px", cursor: 'pointer' }} onClick={() => {
this.setDate("month")
}}>本月</span>
<span style={{ display: "inline-block", marginRight: "8px", cursor: 'pointer' }} onClick={() => {
this.setDate("year")
}}>全年</span>
//点击设置日期
setDate = (type) => {
this.setState({
createStartDate: moment().startOf(type).format('YYYY-MM-DD'),
createEndDate: moment().endOf(type).format('YYYY-MM-DD')
}, () => {
this.queryList()
})
}