egg-validate 显示this.validate is not a function

Created on 30 Oct 2017  ·  10Comments  ·  Source: eggjs/egg

  • Node Version: 8.3.0
  • Egg Version: 1.10.0
  • Plugin Name: egg-validate
  • Plugin Version: 1.0.0
  • Platform: mac
  • Mini Showcase Repository:


正常引入插件
但是会报错 this.validate is not a function
我看了原型链 确实app下有validator
但是没有validate这个方法

RTFM

Most helpful comment

vscode 配置下 "files.autoSave": "onFocusChange", 即可

All 10 comments

this.ctx.validate

Controller 有两种写法的

egg-validate需要手动安装吗 @cwc845982120 @atian25
this.ctx.validate
this.validate
ctx.validate
以上三个输出都是undefined
image

需要,不是内置插件

我已经安装了
package.json

"dependencies": {
        "egg": "^1.9.0",
        "egg-scripts": "^2.1.0",
        "egg-view-nunjucks": "^2.1.4",
        "egg-validate": "^1.0.0"
    }

\config\plugin.js

'use strict';

// had enabled by egg
exports.static = true;
exports.nunjucks = {
    enable: true,
    package: 'egg-view-nunjucks',
};
exports.validate = {
    enable: true,
    package: 'egg-validate',
  };

controller/topics.js

 async index() {
        const { ctx } = this;
        console.log(999);
        console.log(this.validate)
        console.log(this.ctx.validate)
        console.log(ctx.validate)
            // ctx.validate({
            //     page: { format: /\d+/, required: false },
            //     tab: { type: 'enum', values: ['ask', 'share', 'job', 'good'], required: false },
            //     limit: { format: /\d+/, required: false },
            // }, ctx.query);

        ctx.body = await ctx.service.topics.list({
            page: ctx.query.page,
            tab: ctx.query.tab,
            limit: ctx.query.limit,
            mdrender: ctx.query.mdrender !== 'false',
        });
    }

this.ctx.validate
this.validate
ctx.validate
还都是undefined
能指点一二吗
@atian25

提供最小可复现仓库 @lijicheng123

好的 麻烦进去看看 https://github.com/lijicheng123/egg

config/plugin.js 没挂载插件啊

谢谢 ,我的错,vscode 不ctr + s 都不保存
现在好了

vscode 配置下 "files.autoSave": "onFocusChange", 即可

太牛逼了,谢谢

Was this page helpful?
0 / 5 - 0 ratings