JavaScipt__下载

基本js下载思路:

  •   创建a标签,
  •   给a标签创建download属性,
  •   在属性中点击下载。
  •   一般后台会返回file_pathurl进行赋值

实现过程: 

function downLoadeFile(file_path) {

  const a = document.createElement('a');  // 创建a标签

  document.getElementById("downLoadButton").appendChild(a); //添加a标签

  a.setAttribute("href", file_path); // 给标签添加路径

  a.setAttribute("download", 'download'); // 给标签添加download属性

  a.click() //触发

}

export default {

  downLoadeFile,   // 导出方法

}

  

原文地址:https://www.cnblogs.com/GongYaLei/p/8428982.html