koa 接受处理数据
2019-12-18 本文已影响0人
Mokingc
处理数据使用koa-better-body
中间件
安装 npm i koa-better-body -D
处理get数据:ctx.request.query
处理post数据:ctx.request.fields
const body = require('koa-better-body')
let obj = body({ uploadDir: 'upload' })
server.use(obj)
router.post('/issue', async ctx => {
// console.log(ctx.request.body)
// console.log(ctx.request.files)
console.log(ctx.request.fields)
let { title, catalogs, tags, contents } = ctx.request.fields
console.log(title, catalogs, tags, contents)
Article.create({ title: title, catalogs: catalogs, tags: tags, content: contents })
ctx.response.body = 'success'
})