let clickTime = 0
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
open: false
}
}
// 偶数次关闭
handlePanelChange = (value, mode) => {
clickTime += 1
this.setState({
open: clickTime % 2 !== 0,
[key]: value
});
};
handleOpenChange = (open) => {
// 关闭后clickTime 清0, 防止点一次就关闭了,下次打开再点一次就又关闭了
this.setState({ open: open },()=>{clickTime = 0}));
}
render() {
// 初始值
const monthValue = [moment(moment(), 'YYYY-MM'), moment(moment(), 'YYYY-MM')]
return (
<RangePicker
format="YYYY-MM"
mode={['month', 'month']}
placeholder={['开始月份', '结束月份']}
value={monthValue}
open={this.state.open}
onOpenChange={this.handleOpenChange}
onPanelChange={(value, mode) => this.handlePanelChange(value, mode)} />
)
}
}