V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
yantianqi
V2EX  ›  程序员

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

  •  
  •   yantianqi · 2018-01-03 11:00:48 +08:00 · 5487 次点击
    这是一个创建于 2802 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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   ·   实用小工具   ·   5327 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:58 · PVG 14:58 · LAX 23:58 · JFK 02:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.