body-parse使用

 body-parse使用  

  作用:在连接前端和后台的时候,前端传递进来数据无法被node或者express解析,或者解析出来的结果无法被使用,这个时候需要body-parse提高的解释器来对请求数据进行转换。

  安装: npm install body-parse --save

  使用:

const bodyParse=require('body-parse')//引入包
//使用:
//方法一:
var urlencodedParse=bodyParse.urlencoded({extended:false})
//方法二:
var bodyjson= bodyParse.json();
​
//在app.js中使用,意味着同时支持两种请求题,最终得到的都是json对象或者x-www-form-urlencoded的编码方式传递数据
app.use(urlencodedParse);
app.use(bodyjson);

 

 

posted @ 2021-03-28 16:26  焕不涣  阅读(412)  评论(0编辑  收藏  举报