学无先后,达者为师

网站首页 前端文档 正文

前端使用JSON.stringify,传递到后台多了个冒号

作者:大橙子额 更新时间: 2022-03-03 前端文档

场景:前端使用JSON.stringify传递到后台之后报错了,后端发现多了个冒号,在控制台打印出来发现没有冒号。在network中查看数据的时候发现多了个冒号。
解决:审查元素 Network 选项卡 Request Headers,contentType的默认是application/x-www-form-urlencoded表单格式,将contentType改为application/json

 'contentType': 'application/json'

前端是使用vue,封装的axios

export function getList(data) {
  return request({
    url: '/getList',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

原文链接:https://blog.csdn.net/weixin_43043994/article/details/101058969

栏目分类
最近更新