node.js使用multer的req.body为空问题

中间件里req.body为空

img

但是在下面的路由中可以拿到req.body

img

前端vue提交代码,用的是表单提交,elementui

img

拿不到的,还没解析呢。。。你需要在router.post的回调里再挪动一次

img

Nodejs req.body 默认为空。如果使用了 express 框架,可以通过安装body-parser中间件加以解决 也就是说需要使用npm或者yarn安装body-parser中间件,然后在项目主文件中引入body-parser中间件并使用。

var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())