js下载blob文件

下载文件代码

download(url, name) {
    
    
      const x = new XMLHttpRequest();
      x.open('get', url, true);
      x.responseType = 'blob';
      x.onload = () => {
    
    
        const url = window.URL.createObjectURL(x.response);
        const a = document.createElement('a');
        a.href = url;
        a.download = name;
        a.dispatchEvent(new MouseEvent('click'));
      };
      x.send();
    }

猜你喜欢

转载自blog.csdn.net/qq_44732146/article/details/132435381