1.安装 koa-parameter
npm install koa-parameter --save
2.在路由处理之前调用
app.use(parameter(app))
在app文件夹下,index.js中调用
例如
三.使用(在middleware层做校验)
ctx.verifyParams({ goods_name: { type: 'string', required: true }, goods_price: { type: 'number', required: true }, goods_num: { type: 'number', required: true }, goods_img: { type: 'string', required: true }, })
例如
标签:goods,type,app,required,校验,参数,koa2,parameter,true From: https://www.cnblogs.com/guohanting/p/17332544.html