前言
最近更改Node接口时遇到了一些问题, 比如前端以何种方式传参, 后端用何种方式接收等等…
今天花了一小段事件测试了一下, 整理一下结果吧.
一、GET
后端接收query
前端传params.
前端:
axios({
method: "get",
url: "http://localhost:3000/getArticleById",
params: {
article_id: 8,
},
}).then((res) => {
console.log(res);
});
后端:
app.post('/getArticleById', (req, res, next) => {
api.getArticleById(req, res, next);
})
getArticleById(req, res, next) {
console.log("body:" + req.body.article_id)
console.log("params:" + req