一、
接口请求设置为 responseType: ‘blob’
二、
export upload = data => {
retrun request({
url:' ',
method:'post',
resopnseType:'blob',
data
})
}
let file = this.fileCopy [0].raw;
var formData = new FormData();
formData.append('file',file)
upload(formData ).then( async res => {
if (res.data.type === 'application/json'){
//Blob.text()返回一个promise且包含blob所有内容的UTF-8格式的 USVString。
let text = await res.data.text();
let jsonText = await JSON.parse(text)
}else{
const blob = new Blob([res.data],{type:'application/octet-stream;charset=utf-8'})
let link = document.createElement('a')
link.style.display = 'none'
let objectUrl = URL.createObjectURL(blob)
link.href = objectUrl
link.download = '模板.xlsx'
link.click()
URL.revokeObjectUrl(objectUrl)
}
})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)