export default (url) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', 'url', true);
xhr.onprogress = function (e) {
let percent = Math.floor( e.loaded / e.total * 100); // 下载进度
console.log(percent, '进度');
};
xhr.send();
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = event => {
if(xhr.readyState == 4){
if (xhr.status == 200){
const fileName = 'fileName';
let blob = new Blob([xhr.response], {type: 'video/mp4'}); // 文件类型
const downLoadLink = document.createElement('a');
downLoadLink.download = fileName;
downLoadLink.href = URL.createObjectURL(blob);
downLoadLink.click();
}
}
}
}
05-17
1197
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)