赞
踩
- function exportFun (target, url, name) {
- axios({
- method:'POST',
- url: url,
- data: target.query,//请求数据
- responseType: 'blob',//响应类型
- getResponse: true, // 获取整个 response对象
- xsrfHeaderName: 'Authorization',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': getToken(),
- 'lang' : InitLanguage()
- },
- }).then(res=> {
- //let blob = new Blob([res.data], {
- // type: 'application/vnd.ms-excel' //文件格式对应文件后缀xls(比如xlsx/dotx等)
- // })
- const blob = res.data
- // res.data 此时应该是一个blob
- let url = window.URL.createObjectURL(blob)
- const filename = window.decodeURIComponent(res.response.headers.get('Content-disposition').split('filename=')[1]) // 获取文件名
- let link = document.createElement('a')
- link.style.display = 'none'
- link.href = url
- link.download = filename
- document.body.appendChild(link)
- link.click()
- }).catch(error => {
- this.$notify.error({
- title: '错误',
- message: error.message,
- })
- })
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。