这个错误产生的原因是因为 Antd 的版本问题。在旧版本的 Antd 中并不支持 onVisibleChange
这个事件。所以我们需要升级 Antd 到更高的版本,并在代码中添加相应的逻辑。以下是示例代码:
import React from "react";
import { Button, Modal } from "antd";
class MyModal extends React.Component {
state = {
visible: false
};
showModal = () => {
this.setState({
visible: true
});
};
handleOk = e => {
this.setState({
visible: false
});
};
handleCancel = e => {
this.setState({
visible: false
});
};
render() {
return (
Some contents...
Some contents...
Some contents...
);
}
}
export default MyModal;
在这个代码示例中,我们只需要添加 onVisibleChange
事件即可解决这个错误。当然,这个事件只适用于 Antd4.0 或者更高版本。如果你使用的是旧版本的 Antd,可以考虑升级到最新版或者使用其他的备选方案。