【发布时间】:2020-07-01 16:29:15
【问题描述】:
我正在为 ant design file drag and drop upload 和 modal 添加我的 react typescript 项目。我尝试在我拖动或上传文件时只在屏幕上显示模式弹出窗口(不想显示上传的文件只显示模式),我设置了代码但它不起作用,任何人都知道该怎么做正确
谢谢
代码部分在这里
import { Upload, message,Modal, Button } from 'antd';
import { InboxOutlined } from '@ant-design/icons';
const { Dragger } = Upload;
const props = {
name: 'file',
multiple: true,
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
onChange(info) {
const { status } = info.file;
if (status !== 'uploading') {
console.log(info.file, info.fileList);
}
if (status === 'done') {
message.success(`${info.file.name} file uploaded successfully.`);
} else if (status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
interface AppProps { }
interface AppState {
name: string;
}
class App extends Component<AppProps, AppState> {
constructor(props) {
super(props);
this.state = {
name: 'React',
visible: false
};
}
//modal
showModal = (any) => {
this.setState({
visible: "true",
});
};
handleOk = e => {
console.log(e);
this.setState({
visible: false,
});
};
handleCancel = e => {
console.log(e);
this.setState({
visible: false,
});
};
render() {
return (
<div>
<Dragger {...props} onClick={this.showModal}>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">Click or drag file to this area to upload</p>
<p className="ant-upload-hint">
Support for a single or bulk upload. Strictly prohibit from uploading company data or other
band files
</p>
</Dragger>
<div>
<Modal
title="Basic Modal"
visible={this.state.visible}
onOk={this.handleOk}
onCancel={this.handleCancel}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Modal>
</div>
</div>
);
}
}
【问题讨论】:
标签: reactjs antd ant-design-pro react-typescript