- export function tryHideFullScreenLoading() {if (needLoadingRequestCount <= 0) return
- needLoadingRequestCount--
- if (needLoadingRequestCount === 0) {
- endLoading()
- }
- }
- axios.interceptors.request.use(
- config => {
- var token = ''if(typeof Cookies.get('user') ==='undefined'){
- // 此时为空
- }else {
- token = JSON.parse(Cookies.get('user')).token
- }// 注意使用的时候需要引入 cookie 方法, 推荐 js-cookie
- config.data = JSON.stringify(config.data);
- config.headers = {
- 'Content-Type':'application/json'
- }
- if(token != ''){
- config.headers.token = token;
- }
- showFullScreenLoading()
- return config;
- },
- error => {
- return Promise.reject(err);
- }
- );
来源: http://www.qdfuns.com/article/38681/79fee655a2dd02aa157761fcedfafcf8.html