//注意接口格式定义
export const exportDangan = (data) => {
return request.post({
url: '/api/basic/export',
data,
responseType: 'arraybuffer'
})
}
//导出
const ids = ref<string[]>([])
const downAllClick = async () => {
ids.value = []
if (multipleSelection.value.length > 0) {
multipleSelection.value.forEach((item) => {
ids.value.push(item.id)
})
// window.open(`/api/uploads/${id}`)//get请求可直接下载
common
.downFile(ids)
.then((res) => {
let link = document.createElement('a')
/*type就是blob的type,是MIME类型的,可以自己查看MIME类型都有哪些*/
let blogw = new Blob([res.data], { type: 'application/vnd.ms-excel;charset=utf-8' })
let objectUrl = window.URL.createObjectURL(blogw)
link.href = objectUrl
/*blob请求可以拿到 注意是否被拦截器拦截响应头信息只返回data */
let disposition = decodeURI(res.headers['content-disposition'])
let fileName = disposition.substring(disposition.indexOf('filename=') + 9, disposition.length)
link.download = fileName
link.click()
window.URL.revokeObjectURL(objectUrl)
})
.catch((err) => {
ElMessage({
type: 'warning',
message: '文件下载失败'
})
})
}
vue文件流导出
于 2023-12-12 13:28:19 首次发布