虚心求教下:vue下载在edge中无效,IE中可以实现
发布于 3 年前 作者 huaer 1413 次浏览 来自 问答
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利

项目中需要兼容ie和edge 实现下载功能
代码如下:
this.$http.postParam(“file/export”, {
offerId: self.offerId
}, {
responseType: ‘blob’
}).then(data => {
console.log(data)
const content = data;
const blob = new Blob([content], {
type: ‘application/ms-excel’
});
const fileName = “报价单” + moment().format(“YYYY-MM-DD HH:mm:ss”) + ‘.xlsx’;
if(‘download’ in document.createElement(‘a’)) { // 非IE下载
const elink = document.createElement(‘a’);
elink.download = fileName;
elink.style.display = ‘none’;
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
} else { // IE10+下载
navigator.msSaveBlob(blob, fileName);
}
}).catch(function(error) {
console.log(error);
});
IE中已经实现下载,但是在edge中无效
请问是我代码中没兼容edge吗?
新手刚用vue,有表达不准确的,请见谅~

回到顶部