V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
yantianqi
V2EX  ›  程序员

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

  •  
  •   yantianqi · Jan 3, 2018 · 5655 views
    This topic created in 3043 days ago, the information mentioned may be changed or developed.
    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
    })
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2515 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:27 · PVG 16:27 · LAX 01:27 · JFK 04:27
    ♥ Do have faith in what you're doing.