把后端返回的文件流格式转换成正常数据格式
断点调试返回值
network查看返回值
一、blob类型
let stringData:any = await this.blobToString(res);
blobToString(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => {
resolve(reader.result);
};
reader.onerror = reject;
reader.readAsText(blob);
});
}
二、类型为arraybuffer
let enc = new TextDecoder('utf-8')
res = JSON.parse(enc.decode(new Uint8Array(res))) //转化成json对象
if(res.errcode){
this.$message.error(res.errmsg);
}