// 打印
handleexper(id,name){
console.log(id)
this.$axios.post('/borrow/download/'+id,{},
{responseType: 'blob'}).then((res) =>{
console.log(res);
if(res.status!=200){
this.$message.error(res.data.msg)
}else{
//在线预览pdf文件
// var blob = new Blob([res.data], {type:"application/pdf"})
// let fileURL= URL.createObjectURL(blob)
// this.fileURL=fileURL+"?t="+this.sj()+"#toolbar=0"
// this.pdfble=true;
// window.open(fileURL+"#toolbar=0" ,"_blank",'height=450,width=800,fullscreen=0,titlebar=0,status=0,toolbar=0')
// window.open(fileURL+"#toolbar=0")
// this.gofile(fileURL)
const content = res.data
const blob = new Blob([content]) // 构造blob对象
const fileName = '借阅文件'+name+'.pdf' // 导出文件名
if ('download' in document.createElement('a')) {
const link = document.createElement('a') // 创建a标签
link.download = fileName // a标签添加属性
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
this.gofile(link.href)
document.body.appendChild(link)
link.click() // 执行下载
URL.revokeObjectURL(link.href) // 释放url
document.body.removeChild(link) // 释放标签
}
}
})
},
vue下载文件
最新推荐文章于 2024-01-17 15:10:24 发布