zoukankan      html  css  js  c++  java
  • axios添加公共参数

    import qs from 'qs';
    import axios from 'axios';
    
    // 请求的拦截器
    axios.interceptors.request.use(function (config) {
        const token = localStorage.getItem('token')
        const uid = localStorage.getItem('uid')
         // 判断请求的类型
         // 如果是post请求就把默认参数拼到data里面
         // 如果是get请求就拼到params里面
        if(config.method === 'post') {
            let data = qs.parse(config.data)
    
            config.data = qs.stringify({
                token: token,
                uid: uid,
                ...data
            })
        } else if(config.method === 'get') {
            config.params = {
                token: token,
                uid: uid,
                ...config.params
            }
        }
        return config;
      }, function (error) {
        return Promise.reject(error);
      })
  • 相关阅读:
    快速排序
    fedora 配置
    while与do while
    switch选择结构
    if选择结构
    java有参
    java猜拳
    java类的无参方法
    java类与对象
    java数组
  • 原文地址:https://www.cnblogs.com/zwhbk/p/13201738.html
Copyright © 2011-2022 走看看