旅游教育出版社-数字教材移动端
QYF-GitLab1
22 小时以前 8e3ee81b6ed824866734b7034604121f370f4201
src/plugin/axios/index.js
@@ -9,12 +9,12 @@
// 创建 axios 实例
const service = axios.create({
  baseURL: myConfig.requestCtx,
  timeout: myConfig.requestTimeOut // 请求超时时间
  timeout: myConfig.requestTimeOut, // 请求超时时间
});
// 请求拦截器
service.interceptors.request.use(
  config => {
  (config) => {
    // 在请求发送之前做一些处理
    // if (config.url !== "/api/account/loginByPassword") {
    let token = toolClass.getCookie(myConfig.tokenKey);
@@ -32,7 +32,7 @@
    // }
    return config;
  },
  error => {
  (error) => {
    // 发送失败
    Promise.reject(error);
  }
@@ -40,18 +40,14 @@
// 响应拦截器
service.interceptors.response.use(
  response => {
  (response) => {
    // dataAxios 是 axios 返回数据中的 data
    const dataAxios = response.data;
    // 这个状态码是和后端约定的
    const {
      success
    } = dataAxios;
    const { success } = dataAxios;
    if (dataAxios.currentDate) {
      sessionStorage.currentDate = new Date(dataAxios.currentDate).getTime();
    }
    // 根据 code 进行判断
    if (success) {
      return dataAxios.data;
@@ -60,11 +56,11 @@
      console.error(dataAxios.msg);
    }
  },
  error => {
  (error) => {
    if ((error.message = "Network Error")) {
      let loginCode = WeChat.getUrlInfo("weChatLogin");
      if (loginCode.code) {
        WeChat.login(loginCode.code, data => {
        WeChat.login(loginCode.code, (data) => {
          toolClass.setCookie(myConfig.tokenKey, data);
          location.reload();
        });