小工具知识网

当前位置: 首页 > 行业知识 > axios的get和post请求传headers、query、body等参数

行业知识

axios的get和post请求传headers、query、body等参数

2026-11-03 00:41:57 来源:互联网转载

axios的get和post请求传headers、query、body等参数

一、get传headers和query

// 方法一:get请求传query可以拼接在url后面,也可以放在params中const age = 15;const result = await axios.get(`/a?age=${age}&type=1`,{  headers: {    "Content-Type": testApiData.value.extContentType,  },});
// 方法二:get请求传query也可以放在params中const query = {  age: 15,  type: 1,};const result = await axios.get("/a", {  params: query,  headers: {    "Content-Type": testApiData.value.extContentType,  },});

2.post请求传query、body、headers

// 方法一const result = await axios.post("/a", body, {  headers: { "Content-Type": "application/x-www-form-urlencoded" },  params: query});
// 方法二const query = {  age: 15,  type: 1,};const result = await axios({  url: "/a",  method: "post",  data: body,  params: query,  headers: {    "Content-Type": "application/json",  },});

上一篇:如何在Linux使用Docker部署Nexus容器并实现公网访问本地仓库【内网穿透】

下一篇:怎么创建网址域名?