// 请求接口时设置如下
{
headers: {
'Content-Type': 'multipart/form-data',
},
responseType: 'blob'
}
// 接口拿到数据之后的判断
const resInfo: any = await this.blobToObj(res.data)
if(resInfo.code != 200) {
this.$message.error(resInfo.message)
}
// 转换方法
private blobToObj(data: any) {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.readAsText(data, 'utf-8');
reader.onload = function() {
try {
resolve(JSON.parse(reader.result as string))
} catch (error) {
resolve({
code: 200,
message: '获取文件信息成功'
})
}
}
})
}