axios-qs

作者: 冯阳阳的博客 | 来源:发表于2018-11-09 15:05 被阅读0次

记录:

  • 使用Qs,转换请求类型为application/x-www-form-urlencoded;charset=UTF-8,
  • 不使用会使用application/json;charset=UTF-8,根据后台需求来定

不使用qs序列化:

请求类型为application/json

export function post(url, params) {    
    return new Promise((resolve, reject) => {         
        axios.post(url, params)        
        .then(res => {            
            resolve(res.data);           
        })        
        .catch(err => {            
            reject(err.data)        
        })    
    });
}

使用qs

请求:application/x-www-form-urlencoded;charset=UTF-8(默认)

export function post(url, params) {    
    return new Promise((resolve, reject) => {         
        axios.post(url, QS.stringify(params))        
        .then(res => {            
            resolve(res.data);           
        })        
        .catch(err => {            
            reject(err.data)        
        })    
    });
}

相关文章

  • axios-qs

    记录: 使用Qs,转换请求类型为application/x-www-form-urlencoded;charset...

网友评论

      本文标题:axios-qs

      本文链接:https://www.haomeiwen.com/subject/mgloxqtx.html