取消数据请求的loading
Showing
1 changed file
with
11 additions
and
11 deletions
| ... | @@ -2,7 +2,7 @@ import store from '../../store/index' | ... | @@ -2,7 +2,7 @@ import store from '../../store/index' |
| 2 | import axios from 'axios' | 2 | import axios from 'axios' |
| 3 | import router from '../../router' | 3 | import router from '../../router' |
| 4 | import {Message, MessageBox} from 'element-ui' | 4 | import {Message, MessageBox} from 'element-ui' |
| 5 | import { Loading } from 'element-ui'; | 5 | // import { Loading } from 'element-ui'; |
| 6 | import {httpStatus} from '@/api/config' | 6 | import {httpStatus} from '@/api/config' |
| 7 | 7 | ||
| 8 | // 创建一个 axios 实例 | 8 | // 创建一个 axios 实例 |
| ... | @@ -19,7 +19,7 @@ const service = axios.create({ | ... | @@ -19,7 +19,7 @@ const service = axios.create({ |
| 19 | function errorLog() { | 19 | function errorLog() { |
| 20 | //请求完成关闭loading | 20 | //请求完成关闭loading |
| 21 | // this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭 | 21 | // this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭 |
| 22 | loadingInstance.close(); | 22 | // loadingInstance.close(); |
| 23 | // }); | 23 | // }); |
| 24 | MessageBox.alert('报错了请联系管理员', '消息提示', { | 24 | MessageBox.alert('报错了请联系管理员', '消息提示', { |
| 25 | confirmButtonText: '确定', | 25 | confirmButtonText: '确定', |
| ... | @@ -27,7 +27,7 @@ function errorLog() { | ... | @@ -27,7 +27,7 @@ function errorLog() { |
| 27 | }) | 27 | }) |
| 28 | } | 28 | } |
| 29 | //定义loading | 29 | //定义loading |
| 30 | let loadingInstance = null | 30 | // let loadingInstance = null |
| 31 | 31 | ||
| 32 | // 请求拦截器 | 32 | // 请求拦截器 |
| 33 | service.interceptors.request.use( | 33 | service.interceptors.request.use( |
| ... | @@ -37,12 +37,12 @@ service.interceptors.request.use( | ... | @@ -37,12 +37,12 @@ service.interceptors.request.use( |
| 37 | // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改 | 37 | // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改 |
| 38 | // config.headers['authkey'] = token | 38 | // config.headers['authkey'] = token |
| 39 | //请求发送成功显示loading | 39 | //请求发送成功显示loading |
| 40 | loadingInstance = Loading.service({ | 40 | // loadingInstance = Loading.service({ |
| 41 | lock: true, | 41 | // lock: true, |
| 42 | text: 'Loading', | 42 | // text: 'Loading', |
| 43 | spinner: 'el-icon-loading', | 43 | // spinner: 'el-icon-loading', |
| 44 | background: 'rgba(0, 0, 0, 0.5)' | 44 | // background: 'rgba(0, 0, 0, 0.5)' |
| 45 | }); | 45 | // }); |
| 46 | return config | 46 | return config |
| 47 | }, | 47 | }, |
| 48 | error => { | 48 | error => { |
| ... | @@ -59,7 +59,7 @@ service.interceptors.response.use( | ... | @@ -59,7 +59,7 @@ service.interceptors.response.use( |
| 59 | const {code} = dataAxios | 59 | const {code} = dataAxios |
| 60 | //请求完成关闭loading | 60 | //请求完成关闭loading |
| 61 | // this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭 | 61 | // this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭 |
| 62 | loadingInstance.close(); | 62 | // loadingInstance.close(); |
| 63 | // }); | 63 | // }); |
| 64 | // 根据 code 进行判断 | 64 | // 根据 code 进行判断 |
| 65 | if (code === undefined) { | 65 | if (code === undefined) { |
| ... | @@ -90,7 +90,7 @@ service.interceptors.response.use( | ... | @@ -90,7 +90,7 @@ service.interceptors.response.use( |
| 90 | }, | 90 | }, |
| 91 | error => { | 91 | error => { |
| 92 | if (error && error.response) { | 92 | if (error && error.response) { |
| 93 | loadingInstance.close(); | 93 | // loadingInstance.close(); |
| 94 | switch (error.response.status) { | 94 | switch (error.response.status) { |
| 95 | case 400: | 95 | case 400: |
| 96 | error.message = '请求错误'; | 96 | error.message = '请求错误'; | ... | ... |
-
Please register or sign in to post a comment