vue下载pdf ,不预览直接下载

    // 下载文件
    downloadfun(file_name,file_path){
      console.log(file_name)
      var ajax=new XMLHttpRequest();
      ajax.open( "GET", file_path, true);
      ajax.setRequestHeader("Cache-Control","no-cache")
      ajax.setRequestHeader('Access-Control-Allow-Origin', '*');
      ajax.responseType = 'blob';
      ajax.onload = e =>{
        console.log(e)
        let res = e.target.response
        // let blob = new Blob([res],{type: "application/pdf;charset=UTF-8"}) // 这里的res为后端返回的流数据
        let blob = new Blob([res])
        let aLink = document.createElement("a")
        aLink.download = file_name // 下载文件的名字
        aLink.href = URL.createObjectURL(blob)
        aLink.click()
      }
      ajax.send()
    },
Logo

前往低代码交流专区

更多推荐