zoukankan      html  css  js  c++  java
  • 文件下载

    步骤:
    1、获取文件流;
    2、用文件流创建url;
    3、创建a标签,并自动点击
     
    Download({
            filename
          })
            .then(res => {
              // console.log(res);
              let link = document.createElement("a");
              link.style.display = "none";
              link.href = window.URL.createObjectURL(res.data);
              //获取文件名称
              let attachment = res.headers["content-disposition"];
              let fileName = decodeURIComponent(
                attachment.split(";")[1].split("=")[1]
              );
              // console.log(fileName);
              link.download = fileName;

              link.click();
              window.URL.revokeObjectURL(link.href); //释放内存
            })
            .catch(err => {});
  • 相关阅读:
    用户登录
    open >>>文件操作
    随机数
    内置函数
    函数练习
    函数的动态参数
    函数的指定参数
    函数的普通参数
    函数的初步认识
    copy
  • 原文地址:https://www.cnblogs.com/ouyangfeifei/p/14601423.html
Copyright © 2011-2022 走看看