当前位置:网站首页>Download File blob transcoding
Download File blob transcoding
2022-06-25 13:17:00 【liminla!】
// Download the file ( Method 1)
export function download(data, name) {
if (!data) {
return
}
const getDate = new Date().getFullYear() + String((new Date().getMonth() + 1) < 10 ? `0${
String(new Date().getMonth() + 1)}` : (new Date().getMonth() + 1)) + new Date().getDate()
const blob = new Blob([data])
const fileName = `${
name}-${
getDate}.xls`;
if ('download' in document.createElement('a')) {
// No IE browser
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // Download complete remove element
window.URL.revokeObjectURL(url) // release blob object
} else {
// IE 10+
window.navigator.msSaveBlob(blob, fileName)
}
}
// Download the file ( Method 2)
export function download(res, name) {
const newBlob = new Blob([res]);
const anchor = document.createElement("a");
anchor.download = `${
name}.xlsx`;
anchor.href = window.URL.createObjectURL(newBlob);
anchor.click();
}
export function exportData(params) {
const formData = new FormData();
formData.append('jsonParam', params.jsonParam)
return axios({
method: 'get',
url: `${
process.env.VUE_APP_API_URL}/?jsonParam=${
encodeURI(params.jsonParam)}`,
data: formData,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Access-Token': window.localStorage.getItem("token"),
'work-space-id': JSON.parse(window.sessionStorage.getItem("workSpace"))?.id,
responseType: 'blob'
}
})
.then(res => {
download(res.data, ` Query data ${
params.name}`)
return res.data
})
.catch(err => console.log(err));
}
边栏推荐
猜你喜欢

Configuring pytorch in win10 environment

揭秘GaussDB(for Redis):全面对比Codis

515. Find Largest Value in Each Tree Row
![[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer](/img/77/715454c8203d722e246ed70e1fe0d8.png)
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer

Sword finger offer II 025 Adding two numbers in a linked list

Sword finger offer day 3 string (simple)

AI assisted paper drawing of PPT drawing

关于猜数字游戏的实现

Koa 框架

Conway's law can not be flexibly applied as an architect?
随机推荐
康威定律,作为架构师还不会灵活运用?
[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box
KVM 脚本管理 —— 筑梦之路
Sword finger offer 04 Find in 2D array
Restful and RPC
mysql导入导出数据到excel表日期出现问题
剑指offer 第 3 天字符串(简单)
[machine learning] parameter learning and gradient descent
时间过滤器(el-table)中使用
JVM参数解释
解析數倉lazyagg查詢重寫優化
Used in time filter (EL table)
À propos du stockage des données en mémoire
leetcode - 384. 打乱数组
字符串入门十八讲合集四
Sword finger offer II 028 Flatten multi-level bidirectional linked list
关于三子棋游戏的简易实现与N子棋胜利判断方法
Introduction to mongodb chapter 01 introduction to mongodb
指针,它那些不得不说的题目
Jenkins pipeline uses