`

Content-Type为 application/x-www-form-urlencoded格式data结构

阅读更多
export function fetch(requestUrl, params = '', headers = { 'Content-Type': 'application/x-www-form-urlencoded' }) {
    return axios({
        url: requestUrl,
        method: 'post',
        data: params,
        headers: headers,
        timeout:1000*60*60
    })
};

 一开始这么写会出现这个以下问题,多了个冒号




 

正常写法是引入qs:

import axios from 'axios'
// Content-Type = application/x-www-form-urlencoded 需导入qs才能获取参数
var qs = require('qs');

// 封装post请求
export function fetch(requestUrl, params = '', headers = { 'Content-Type': 'application/x-www-form-urlencoded' }) {
    return axios({
        url: requestUrl,
        method: 'post',
        data: qs.stringify(params),
        headers: headers,
        timeout:1000*60*60
    })
};

 

  • 大小: 5.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics