Commit 5993a1ed by 袁晓帅

修改下载文件不成功的问题

parent dcb26030
...@@ -184,14 +184,18 @@ export default { ...@@ -184,14 +184,18 @@ export default {
this.$axios({ this.$axios({
method: 'post', method: 'post',
url: '/carParking/carExport', url: '/carParking/carExport',
data:{}, data:{
c: 100,
p: 1
},
responseType:'blob',
headers: { headers: {
'Content-Type': 'application/json;charset=UTF-8', //设置请求头请求格式为JSON 'Content-Type': 'application/json;charset=UTF-8', //设置请求头请求格式为JSON
token: window.sessionStorage.getItem('token'), token: window.sessionStorage.getItem('token'),
projectId: window.sessionStorage.getItem('projectId') projectId: window.sessionStorage.getItem('projectId')
} }
}).then(res => { }).then(res => {
let blob = new Blob([res], {type: "application/vnd.ms-excel"}); // res就是接口返回的文件流了 let blob = new Blob([res.data], {type: "application/vnd.ms-excel"}); // res就是接口返回的文件流了
let objectUrl = URL.createObjectURL(blob); let objectUrl = URL.createObjectURL(blob);
window.location.href = objectUrl; window.location.href = objectUrl;
}); });
......
...@@ -45,13 +45,15 @@ axios.interceptors.request.use(config => { ...@@ -45,13 +45,15 @@ axios.interceptors.request.use(config => {
// 设置拦截器 // 设置拦截器
axios.interceptors.response.use(function (response) { axios.interceptors.response.use(function (response) {
console.log(response.config.url) console.log(response.config.url)
if (response.data.code === '0') { if (response.data.code === '0') {
return response return response
} else if (response.data.code === 'BASE_00004') { } else if (response.data.code === 'BASE_00004') {
store.dispatch('clearCancel') store.dispatch('clearCancel')
alert('登录失效,请重新登录', '温馨提示') alert('登录失效,请重新登录', '温馨提示')
router.push('/login') router.push('/login')
return false return false
} else if (response.data.type === 'application/vnd.ms-excel') {
return response
} else { } else {
// 在添加其他的错误码判断 // 在添加其他的错误码判断
if (response.data.msg) { if (response.data.msg) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment