谷歌内核正常,IE下载无后缀名,打不开
- 本次项目需要下载的文件就两种格式xlsx和zip
- 所以走ie时手动添加后缀名就可以搞定了
export const download = async({ url, params, method = 'post', type = 'xlsx' }) => {
const isget = method.toLowerCase() === 'get';
const obj = isget ? { params } : { data: params };
const baseURL = process.env.VUE_APP_BASE_API + url
try {
const { data } = await axios({ baseURL, method, ...obj })
if (data.code) {
window.alert(data.message || '网络繁忙,请稍后重试');
} else {
axios({ baseURL, method, ...obj, responseType: 'arraybuffer' })
.then(res => {
res._params = params
_download(res, type);
}).catch(err => {
window.alert(err.message || '网络繁忙,请稍后重试');
})
}
} catch (error) {
console.log(error);
}
}
const _download = (res, _type)