美文网首页
Vue 跨域下载或读取文件

Vue 跨域下载或读取文件

作者: Yohann丶blog | 来源:发表于2022-06-09 14:01 被阅读0次
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
}

相关文章

网友评论

      本文标题:Vue 跨域下载或读取文件

      本文链接:https://www.haomeiwen.com/subject/qddmmrtx.html