实现效果
实现逻辑
import React, { useState } from 'react';
const ParentComponent= () => {
const [dates, setDates] = useState(null);
const disabledDate = (current) => {
if (!dates) {
return false;
}
const tooLate = dates[0] && current.diff(dates[0], 'days') > 360;
const tooEarly = dates[1] && dates[1].diff(current, 'days') > 360;
return !!tooEarly || !!tooLate;
};
return (
<div>
<RangePicker
picker="month"
defaultValue={[moment().startOf('month'), moment().endOf('month')]}
allowClear={false}
disabledDate={disabledDate}
onCalendarChange={(val) => setDates(val)}
/>
</div>
)
};
export default ParentComponent;
注:本人前端小白 ,如有不对的地方还请多多指教