axios: get() 请求/post()请求
get()请求
axios.get("url",{
params:{
//所需要发送数据
}
}).then(res=> {
console.log(res)
}).catch(err => {
});
node.js服务端接受get请求
app.get('url',(req,res)=>{
//接收前端参数
cosnt userInfo = req.query
//给前端发送参数
res.send()
})
post()请求
axios.get("url",{
//所需要发送数据
}).then(res=> {
console.log(res)
}).catch(err => {
});
node.js服务端接受post请求
//express框架没有对post请求参数的引入方式用第三方包body-parser
npm i body-parser
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post('url',(req,res)=>{
//接收前端参数
cosnt userInfo = req.body
//给前端发送参数
res.send()
})