axios.js 1.07 KB
/*
 * @Date: 2023-10-27 11:12:24
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2023-10-27 11:13:00
 * @FilePath: /vue-flow-editor/doc/axios.js
 * @Description: 文件描述
 */
import axios from 'axios';

axios.defaults.params = {
  f: 'custom_form',
};

/**
 * @description 请求拦截器
 */
axios.interceptors.request.use(
  config => {
    // const url_params = parseQueryString(location.href);
    // GET请求默认打上时间戳,避免从缓存中拿数据。
    const timestamp = config.method === 'get' ? (new Date()).valueOf() : '';
    /**
     * POST PHP需要修改数据格式
     * 序列化POST请求时需要屏蔽上传相关接口,上传相关接口序列化后报错
     */
    // 绑定默认请求头
    config.params = { ...config.params, timestamp }
    return config;
  },
  error => {
    // 请求错误处理
    return Promise.reject(error);
  });

/**
 * @description 响应拦截器
 */
axios.interceptors.response.use(
  response => {
    return response;
  },
  error => {
    return Promise.reject(error);
  });

export default axios;