代码:
this.props.dispatch({
type: 'ResourcePool/down',
payload: { path: xzURL }
}).then(ret => {
if (ret && ret.file) {
console.log(ret,'ret-->')
ret.file.then(aa => {
const files = window.URL.createObjectURL(aa);
let link = document.createElement('a');
link.href = files;
if (ret.name) {//如果后端给了文件名称
link.download = decodeURI(ret.name.split(';filename')[0]);
} else {
link.download = decodeURI(`下载文件.${this.state.fileType}`);
}
link.click();
});
}
})
控制台:
控制台console.log日志输出
用JS形成a标签 效果等同于将文件给到<a></a>标签src