- 导入moment库和antd库的样式文件。
import moment from 'moment';
import 'antd/dist/antd.css';
- 修改DatePicker组件的defaultValue,将其设为moment对象。
- 在modal组件中增加wrappedComponentRef属性,并将其绑定到一个ref。
this.calendarRef = form}/>
- 在modal组件中增加onOk事件,并通过ref访问DatePicker组件,进行操作。
this.calendarRef = form}
onOk={() => {
const calendarValue = this.calendarRef.props.defaultValue.format('YYYY-MM-DD');
console.log(calendarValue);
}}
/>
通过上述方法,可以使Ant Design/antd日历组件在模态框内正常工作。