createObjectURL我用过,window.navigator.msSaveOrOpenBlob还没用过。记一下.
聊天群【前端苞米地-2号地】的记录:
用save-file包吧
或者直接使用createObjectURL
https://developer.mozilla.org/zh-CN/docs/Web/API/URL/createObjectURL
const blob = data
const url = window.URL // || window.webkitURL || window.moxURL
// 创建下载链接
const downloadHref = url.createObjectURL(blob)
let fileName = 'xxx'
let link = document.createElement('a');
link.download = fileName;
link.style.display = 'none';
link.href = downloadHref
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href); // 释放URL 对象
document.body.removeChild(link);
请求时候 responseType: ‘blob’
createObjectURL不支持IE11
ie11 可以用 window.navigator.msSaveOrOpenBlob