调用
this.$download.url('/api/v1/org/question/exportData', datVal, `${this.questMess.name}.xlsx`);
js文件
import { saveAs } from 'file-saver' import axios from 'axios' import { getToken } from '@/utils/util' import { tansParams } from "@/utils/ruoyi"; // const baseURL = process.env.VUE_APP_API_URL //const baseURL = 'https://rly.zgshzyp.com' //const baseURL = 'http://localhost:8080' // console.log(baseURL) // var baseURL = '' // if (process.env.NODE_ENV == 'production') { // baseURL = process.env.VUE_APP_API_URL // } else if (process.env.NODE_ENV == 'test') { // baseURL = process.env.VUE_APP_API_URL // } else if (process.env.NODE_ENV == 'test1') { // baseURL = process.env.VUE_APP_API_URL // } export default { // + "&delete=" + isDelete //如果这里设置值 又不传参 导致后台报错 默认传Y name(urlBase, name, isDelete = true) { // var url = baseURL + "/api/v1/common/downloadTemple?fileName=" + encodeURI(name) var url = urlBase console.log(url) let index = url.lastIndexOf(".") let strType = urlBase.substring(index, url.length); let newName = name + strType console.log(newName) // return axios({ method: 'get', url: url, responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { console.log('再这里开始的') // console.log(res) // console.log(res.data) // console.log(res.headers) // console.log(res.headers['download-filename']) // console.log(name) // console.log('end') const blob = new Blob([res.data]) // this.saveAs(blob, decodeURI(res.headers['download-filename'])) this.saveAs(blob, newName) }) }, resource(resource) { var url = baseURL + "/api/v1/common/download/resource?resource=" + encodeURI(resource); axios({ method: 'get', url: url, responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { const blob = new Blob([res.data]) this.saveAs(blob, decodeURI(res.headers['download-filename'])) }) }, zip(url, name) { var url = baseURL + url axios({ method: 'get', url: url, responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { const blob = new Blob([res.data], { type: 'application/zip' }) this.saveAs(blob, name) }) }, // ly20221031 url,params url(urlBase,params, name,type) { var url = urlBase axios({ method: type||'post', url: url, params, responseType: 'blob', data:params, headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { const blob = new Blob([res.data]) this.saveAs(blob, name) }) }, saveAs(text, name, opts) { saveAs(text, name, opts); } }
标签:console,name,url,res,baseURL,js,实例,blob,download From: https://www.cnblogs.com/dianzan/p/16857221.html