一.http.js文件
import Axios from 'axios'
import api from './api' //存放接口的文件
import Vue from 'vue'
import router from '../router'
import cookle from '../store/cookle.js' //封装cookie的方法
var qs = require('qs'); //用于转换post参数
import { Message,Loading } from 'element-ui'; //element库的消息提示,可以不用
//获取登陆cacheKey 可以用于判断是否登录过期
function getCachekey() {
return cookle.getCookie('cacheKey');
}
let loading; //定义loading变量
function startLoading() { //使用Element loading-start 方法
loading = Loading.service({
lock: true,
text: '加载数据中……',
background: 'rgba(0, 0, 0, 0.3)'
})
}
function endLoading() { //使用Element loading-close 方法
loading.close()
}
//那么 showFullScreenLoading() tryHideFullScreenLoading() 要干的事儿就是将同一时刻的请求合并。
//声明一个变量 needLoadingRequestCount,每次调用showFullScreenLoading方法 needLoadingRequestCount + 1。
//调用tryHideFullScreenLoading()方法,