get方法获取参数:
app.get('/api/user/login', function(req, res) {
console.log(req.query.username);
});
post方法获取参数:
app.post('/api/user/login', function(req, res) {
console.log(req.body.username);
});
使用axios请求api,我个人更倾向下边的写法:
post:
axios({
method: 'post',
url: ajaxUrl,
data: formData
}).then(res =>{
res = res.data;
}).catch(err =>{
});
get:
axios({
method: 'GET',
url: ajaxUrl,
params: data,
}).then(res => {
res = res.data;
}).catch(err => {
})