赞
踩
import axios from 'axios' import { Loading } from 'element-ui' axios.defaults.baseURL = 'http://192.168.0.6:3000' window._server = 'http://192.168.0.6:3000' // 请求超时时间 axios.defaults.timeout = 10000 // 设置post请求头 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' // loading进度条设置 let globalLoading function startLoading () { globalLoading = Loading.service({ lock: true, text: '加载中…', background: 'rgba(0, 0, 0, 0.7)' }) } function endLoading () { setTimeout(() => { globalLoading.close() }, 2000) } let needLoadingRequestCount = 0 export function showFullScreenLoading () { if (needLoadingRequestCount === 0) { startLoading() } needLoadingRequestCount++ } export function tryHideFullScreenLoading () { if (needLoadingRequestCount <= 0) return needLoadingRequestCount-- if (needLoadingRequestCount === 0) { endLoading() } } // http request 拦截器 axios.interceptors.request.use( config => { showFullScreenLoading() return config }, err => { return Promise.reject(err) } ) // 响应拦截器 axios.interceptors.response.use( response => { tryHideFullScreenLoading() return Promise.reject(response) }, error => { return Promise.reject(error.response) } )
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。