Merge remote-tracking branch 'origin/master'
Showing
1 changed file
with
18 additions
and
0 deletions
| ... | @@ -2,6 +2,7 @@ import store from '../../store/index' | ... | @@ -2,6 +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 {httpStatus} from '@/api/config' | 6 | import {httpStatus} from '@/api/config' |
| 6 | 7 | ||
| 7 | // 创建一个 axios 实例 | 8 | // 创建一个 axios 实例 |
| ... | @@ -16,11 +17,17 @@ const service = axios.create({ | ... | @@ -16,11 +17,17 @@ const service = axios.create({ |
| 16 | }) | 17 | }) |
| 17 | 18 | ||
| 18 | function errorLog() { | 19 | function errorLog() { |
| 20 | //请求完成关闭loading | ||
| 21 | // this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭 | ||
| 22 | loadingInstance.close(); | ||
| 23 | // }); | ||
| 19 | MessageBox.alert('报错了请联系管理员', '消息提示', { | 24 | MessageBox.alert('报错了请联系管理员', '消息提示', { |
| 20 | confirmButtonText: '确定', | 25 | confirmButtonText: '确定', |
| 21 | type: 'warning' | 26 | type: 'warning' |
| 22 | }) | 27 | }) |
| 23 | } | 28 | } |
| 29 | //定义loading | ||
| 30 | let loadingInstance = null | ||
| 24 | 31 | ||
| 25 | // 请求拦截器 | 32 | // 请求拦截器 |
| 26 | service.interceptors.request.use( | 33 | service.interceptors.request.use( |
| ... | @@ -29,6 +36,13 @@ service.interceptors.request.use( | ... | @@ -29,6 +36,13 @@ service.interceptors.request.use( |
| 29 | // const token = util.cookies.get('token') | 36 | // const token = util.cookies.get('token') |
| 30 | // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改 | 37 | // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改 |
| 31 | // config.headers['authkey'] = token | 38 | // config.headers['authkey'] = token |
| 39 | //请求发送成功显示loading | ||
| 40 | loadingInstance = Loading.service({ | ||
| 41 | lock: true, | ||
| 42 | text: 'Loading', | ||
| 43 | spinner: 'el-icon-loading', | ||
| 44 | background: 'rgba(0, 0, 0, 0.5)' | ||
| 45 | }); | ||
| 32 | return config | 46 | return config |
| 33 | }, | 47 | }, |
| 34 | error => { | 48 | error => { |
| ... | @@ -43,6 +57,10 @@ service.interceptors.response.use( | ... | @@ -43,6 +57,10 @@ service.interceptors.response.use( |
| 43 | // dataAxios 是 axios 返回数据中的 data | 57 | // dataAxios 是 axios 返回数据中的 data |
| 44 | const dataAxios = response.data | 58 | const dataAxios = response.data |
| 45 | const {code} = dataAxios | 59 | const {code} = dataAxios |
| 60 | //请求完成关闭loading | ||
| 61 | // this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭 | ||
| 62 | loadingInstance.close(); | ||
| 63 | // }); | ||
| 46 | // 根据 code 进行判断 | 64 | // 根据 code 进行判断 |
| 47 | if (code === undefined) { | 65 | if (code === undefined) { |
| 48 | // 如果没有 code 代表这不是项目后端开发的接口 比如可能是 D2Admin 请求最新版本 | 66 | // 如果没有 code 代表这不是项目后端开发的接口 比如可能是 D2Admin 请求最新版本 | ... | ... |
-
Please register or sign in to post a comment