1、下载

let url = window.URL.createObjectURL(new Blob([res.data]))
// 生成一个a标签
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
// 生成时间戳
let timestamp = new Date().getTime()
link.download = timestamp + '.txt'
document.body.appendChild(link)
link.click()
link.remove() 

2、下载流文件

that.percentage=100
const blob = new Blob([res1.data], { type: 'application/zip' }) // new一个二进制对象
const url = window.URL.createObjectURL(blob) // 转化为url
const link = document.createElement('a') // 创建个a标签
link.href = url
link.download = that.projectNameTitle + (new Date()).getTime()// 重命名
link.click()
URL.revokeObjectURL(url)

axios返回值要设为流
responseType:‘blob’,

Logo

前往低代码交流专区

更多推荐