由FormData表单上传数据的时候Node POST传输并未接收到数据,写文章记录一下,希望可以帮到大家
Vue.js 接口
export function login (formData) {
const formDatas = new FormData();
formDatas.append('username', formData.username)
formDatas.append('password', formData.password)
return request({
url: '/login',
method: 'post',
data: formDatas
})
}
服务端:
app.post('/login', (req, res) => {
console.log(req.body)
res.send(req.body)
})
输出:
接下来看下POST行为如何接收参数
npm i connect-multiparty //安装依赖包
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
//加入multipartMiddleware进行解析
app.post('/login',multipartMiddleware, (req, res) => {
console.log(req.body)
res.send(req.body)
})
成功: