axios的get和post請(qǐng)求傳headers、query、body等參數(shù)
一、get傳headers和query
// 方法一:get請(qǐng)求傳query可以拼接在url后面,也可以放在params中
const age = 15;
const result = await axios.get(`/a?age=${age}&type=1`,{
headers: {
"Content-Type": testApiData.value.extContentType,
},
});
// 方法二:get請(qǐng)求傳query也可以放在params中
const query = {
age: 15,
type: 1,
};
const result = await axios.get("/a", {
params: query,
headers: {
"Content-Type": testApiData.value.extContentType,
},
});
2.post請(qǐng)求傳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",
},
});
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-805854.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-805854.html
到了這里,關(guān)于axios的get和post請(qǐng)求傳headers、query、body等參數(shù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!