做了个antd的上传简单封装,很烦。主要用的方法就是使用customRequest 这个覆盖上传组件的默认上传,实现自定义上传。有的地方可能比较low 因为我不知道其他方法。。
import React from 'react'
import { Icon, Button, Upload } from 'antd';
import { uploadimg } from '../../api/login' // 封装的上传路径
export default class FileUpload extends React.Component {
constructor(props) {
super(props)
this.state = {
fileList: []
}
this.removeFile = this.removeFile.bind(this)
}
removeFile(file){
console.log(file)
this.state.fileList.map((v,i)=>{
if(file.uid === v.uid){
this.state.fileList.splice(i,1)
this.setState({fileList:this.state.fileList})
this.props.onChange(this.state.fileList)
}
})
}
customRequest = (option) => {