egg-async-validator-best
v1.0.0
Published
https://github.com/yiminghe/async-validator # egg-async-validator-best
Downloads
10
Maintainers
Readme
https://github.com/yiminghe/async-validator
egg-async-validator-best
Install
$ npm i egg-async-validator-best --save
Usage
// {app_root}/config/plugin.js
exports.asyncValidatorBest = {
enable: true,
package: 'egg-async-validator-best',
};
Configuration
// {app_root}/config/config.default.js
exports.asyncValidatorBest = {
};
see config/config.default.js for more detail.
Example
- 基于async-validator 的egg验证插件
//post 验证
const rule = {
lng: { type: 'string', required: true, message: '必填项' },
lat: { type: 'string', required: true }
}
await this.ctx.validate(rule) //默认校验 this.ctx.request.body
//or
//get
await this.ctx.validate(rule,this.ctx.query)
//自定义
await this.ctx.validate(rule,{
lng:'11',
lat:""
})
Questions & Suggestions
Please open an issue here.