antd中实现下载和以前用jquery没什么太大的区别,就是用Blob对象进行处理
downloadFile=(e)=>{
const fileName=rowData.activeDepotName;//说白了就是给文件个名字
this.props.dispatch({//发送请求
type:'pluginInfo/download',
payload:{},//参数
callback:(response)=>{
//这块是下载的重点
const blob=new Blob([response]);//创建blob对象
const aLink=document.createElement('a');//创建a链接
aLink.style.display='none';
aLink.href=blob;
aLink.download=fileName;
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);//点击完成后记得删除创建的链接
}
})
}
render(){
.
.
.
return (
<Button onClik={this.downloadFile}>下载</Button>
)
}
这样点击后就会自动调用浏览器的下载功能进行文件下载。
下面记录一个自己开发中遇到的问题及解决办法:
a