nodejs:Koa,哈巴狗中的形式给出未定义
nodejs: Koa , form in pug gives undefined
我在 pug 中有一个表单,只有一个输入
form(action="/" method="POST")
label Enter URL to shorten
br
input(name="url" type="url")
button(type="submit") Submit
我使用 koa-pug 获取输入
async function handleForm (ctx) {
console.log(ctx.request.body);
}
然而,这记录未定义
我也使用 koa-body 作为主体解析器
app.use(body());
在您的表单中,您使用 POST
方法调用 koa 后端。所以要得到正文,你需要使用像 co-body
,
这样的东西
...
const parse = require('co-body');
...
async function handleForm (ctx) {
let body = await parse(ctx);
console.log(body);
}
我在 pug 中有一个表单,只有一个输入
form(action="/" method="POST")
label Enter URL to shorten
br
input(name="url" type="url")
button(type="submit") Submit
我使用 koa-pug 获取输入
async function handleForm (ctx) {
console.log(ctx.request.body);
}
然而,这记录未定义
我也使用 koa-body 作为主体解析器
app.use(body());
在您的表单中,您使用 POST
方法调用 koa 后端。所以要得到正文,你需要使用像 co-body
,
...
const parse = require('co-body');
...
async function handleForm (ctx) {
let body = await parse(ctx);
console.log(body);
}