当前位置:网站首页>koa2 接收不到post方法提交的formData数据(值: {})
koa2 接收不到post方法提交的formData数据(值: {})
2022-07-20 05:30:00 【cc_King】
解决办法
- 首先使用的肯定是
koa-body
这个中间件; - 其次,只用配置一下参数就可以了;
const Koa = require('koa')
const app = new Koa()
const bodyparser = require('koa-body')
app.use(bodyparser({
enableTypes: ['json', 'form', 'text'],
multipart: true // ***** 就是这个 (是否支持 multipart-formdate 的表单)
}))
- 最后 在路由里面就可使用了
router.post('/register', function (ctx, next) {
console.log(ctx.request.body); // 这里就可以得到前端传来的参数了
ctx.response.body = "";
})
小警告(注意点)
const bodyparser = require('koa-body')({
// 如果你在这里配置了一次参数
multipart: true
})
app.use(bodyparser({
// 这里又配置一次,name这个配置会覆盖上面的,也就是说上面的配置不生效
enableTypes: ['json', 'form', 'text'],
}))
// 一开始就是吃了这个亏,白忙了半天
附上配置说明文档
边栏推荐
- 2022-07-19-use shell to activate CONDA environment
- [dish of learning notes, dog learning C] minesweeping game
- 【学习笔记之菜Dog学C】详解操作符
- CV-Paper【1】:Deep Residual Learning for Image Recognition
- 【学习笔记之菜Dog学C】数据存储
- Millet college reported an error 503 when registering the gateway gateway with Nacos
- JMeter stress test is set to send a request every second
- 虚拟DOM,和实际的DOM有何不同?
- [dish of learning notes, dog learning C] getting to know the pointer for the first time
- [dish of learning notes dog learning C] data storage
猜你喜欢
Towards Representation Alignment and Uniformity in Collaborative Filtering
【学习笔记之菜Dog学C】循环语句
OpenLayers 画圆画椭圆
Implementation of fruit and vegetable mall management system based on SSM
CV-Paper【1】:Deep Residual Learning for Image Recognition
数组常用方法
背包问题(01背包/完全背包解释)
JMeter stress test is set to send a request every second
B. Making Towers
【学习笔记之菜Dog学C】详解数组名
随机推荐
后悔过去,不如奋斗将来
Apache Doris Binlog Load使用方法及示例
化工企业如何选择双重预防机制数字化服务商
虚拟DOM,和实际的DOM有何不同?
js常见面试题
ES6中Symbol、迭代器和生成器基本语法
【学习笔记之菜Dog学C】练习
05—— mvvm 模型
B. Difference of GCDs
[dish of learning notes, dog learning C] first learn operators and original code, inverse code, complement code
[sort] bucket sort and cardinal sort
Matlab digital image processing experiment 5: morphological image processing
【学习笔记之菜Dog学C】指针初阶
Apache Doris Oracle ODBC appearance User Guide
作为程序员的思考
Asynchronous processing of readfile blocking
Graduation season -- use technology of various application scenarios
P1913 战斗之伞兵
Win10 builds Presto development environment based on idea
【学习笔记之菜Dog学C】数组