GET 使用 params
,参数默认会被序列化到 url
request
.get("/api/v1/xxx", {
params: {
id: 1
}
})
request
.get("/api/v1/xxx?id=1")

POST,PUT,DELETE 使用 data
request
.post("/api/v1/user", {
data: {
name: "Mike"
}
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
如果 Content-Type
设置为 application/json
,数据在 Request Payload
headers: { 'Content-Type': 'application/json' },

如果 Content-Type
设置为 multipart/form-data
,数据在 Form Data
request
.post("/api/v1/user", {
headers: { 'Content-Type': 'multipart/form-data' },
data: {
name: "Mike"
},
requestType: 'form' // 注意加个这个
})

网友评论