流文件下载函数

151 阅读1分钟

流文件下载函数

 export function getFileArrayBuffer(url) {
  return new Promise((resolve, reject) => {
    const xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', url, true);
    xmlhttp.responseType = 'blob';
    xmlhttp.onload = function () {
      if (xmlhttp.status === 200) {
        resolve(xmlhttp.response);
      } else {
        reject(xmlhttp.onerror);
      }
    };
    xmlhttp.send();
  });
}

项目用了axios,为什么还需要单独写这个ajax请求的下载函数,因为axios有跨域限制。