1.用过原生node.js 拿post请求的参数的同学就知道有多么麻烦
但是 使用express框架的童鞋 使用一个body-parser中间件 一个req.body 就拿到了 参数
2.第一步先安装
npm i body-parser -S
3.引入
const bodyParser=require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
4.使用
router.post('/denglu',(req,res)=>{
console.log(req.body); // 这样就拿到了 前台传来的参数了
res.send({code:'200',msg:'登陆成功!');
})