马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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",
- },
- });
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |