V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yantianqi
V2EX  ›  程序员

axios 请求参数序列化怎么设置

  •  
  •   yantianqi · 2018-01-03 11:00:48 +08:00 · 5370 次点击
    这是一个创建于 2313 天前的主题,其中的信息可能已经有所发展或是发生改变。
    const _ajax = axios.create({
      baseURL: baseURL,
      headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
      withCredentials: withCredentials,
      // 参数序列化
      paramsSerializer: function(params) {
        return qs.stringify(params, {arrayFormat: 'repeat'})
      }
    })
    

    上面写的参数序列化不可以吗? 下面这种拦截却可以

    _ajax.interceptors.request.use(function(config) {
      config.data = qs.stringify(config.data, {arrayFormat: 'repeat'});
      console.log(cofig.data)
      return config
    })
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2436 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:13 · PVG 16:13 · LAX 01:13 · JFK 04:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.