js 流下載檔案
阿新 • • 發佈:2021-09-28
importvuefrom'vue'
import{ACCESS_TOKEN}from'@admin/store/mutation-types'
import{cloneDeep}from'lodash'
importaxiosfrom'axios'
importdownloaderfrom'downloadjs'
downList(type){
letparam={
type:type
}
axios({
method:'get',
url:process.env.VUE_APP_BASE_API+'/speed-progress/selectExcl',
params:param,
headers:{
'Content-Type':'application/x-www-form-urlencoded',
'X-Access-Token':vue.ls.get(ACCESS_TOKEN),
},
responseType:"blob"
}).then((res)=>{
console.log(res)
constfileName=res.headers['content-disposition']
?window.decodeURI(res.headers['content-disposition'].split('=')[1],'UTF-8',):'data.csv'
constextension=fileName.split('.')[1]
if(extension=='csv'){
downloader(res.data,fileName)
}
else{
downloader(newBlob([res.data],{type:'application/'+extension}),fileName)
}
})
},