Vue 跨域下载或读取文件

2022-06-09  本文已影响0人  Yohann丶blog
image.png
export async function download(file_url, file_name) {
  let res = await Axios({
    method: "get",
    url: file_url,
    responseType: "blob"
  });
  let newUrl = window.URL.createObjectURL(res.data);
  let a = document.createElement("a");
  a.href = newUrl;
  a.download = file_name;
  a.click();
  a.remove();
  window.URL.revokeObjectURL(newUrl);
}
export async function read(text_url) {
  let res = await Axios({
    method: "get",
    url: text_url,
    responseType: "text"
  });
  return res.data
}
上一篇 下一篇

猜你喜欢

热点阅读