如请求类型为bolb时
exportFileLedger: (params) => {
return request.get(`${service}/export/file/ledger`, { responseType: "blob", params });
},
获取方法为
if (
(response.data instanceof Blob &&
response.data.type === "application/json")
) {
response.data.text().then((text) => {
const json = JSON.parse(text);
window.$message.warning(json.description);
});
// 非Blob类型的报错信息处理
}
如请求类型为arraybuffer时
exportFileLedger: (params) => {
return request.get(`${service}/export/file/ledger`, { responseType: "arraybuffer", params });
},
获取方法为
if (response.data instanceof ArrayBuffer) {
// 将ArrayBuffer转换为Uint8Array
const uint8Array = new Uint8Array(response.data);
// 将Uint8Array转换为字符串
const textDecoder = new TextDecoder('utf-8');
const text = textDecoder.decode(uint8Array);
// 尝试将字符串解析为JSON对象
const json = JSON.parse(text);
window.$message.warning(json.description);
}