【问题标题】:Ant design drag and drop uploading after showing modal popup显示模态弹窗后的Ant设计拖放上传
【发布时间】:2020-07-01 16:29:15
【问题描述】:

我正在为 ant design file drag and drop uploadmodal 添加我的 react typescript 项目。我尝试在我拖动或上传文件时只在屏幕上显示模式弹出窗口(不想显示上传的文件只显示模式),我设置了代码但它不起作用,任何人都知道该怎么做正确

谢谢

stack blitz here

代码部分在这里

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


    【解决方案1】:

    我找到了解决办法

    我把这个onClick={this.showModal}改成onChange={this.showModal}

    把状态放在这里

     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.`);
        }
      this.showModal
      },
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多