egg icon indicating copy to clipboard operation
egg copied to clipboard

中间件里访问不到ctx

Open justinli0709 opened this issue 9 years ago • 6 comments

  • Node Version:
  • Egg Version:
  • Plugin Name:
  • Plugin Version:
  • Platform:

justinli0709 avatar Mar 27 '17 03:03 justinli0709

第一个参数是 ctx

justinli0709 [email protected]于2017年3月27日 周一11:51写道:

  • Node Version:
  • Egg Version:
  • Plugin Name:
  • Plugin Version:
  • Platform:

//auth.js module.exports = () => { return async(ctx, next) => { console.log('auth'); console.log(this.ctx); await next(); console.log(this.ctx); }; };

ctx为undefined

请问我应该如何写?多谢!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eggjs/egg/issues/658, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWA1XLRSUYI1v64SuZQK65KRea6iU61ks5rpzJdgaJpZM4Mpw4f .

popomore avatar Mar 27 '17 03:03 popomore

你好,中间件里访问不到ctx,应该怎么写?后来解决了吗?在线等🙈

xjchenhao avatar May 27 '17 01:05 xjchenhao

@xjchenhao 阅读下 https://eggjs.org/zh-cn/basics/objects.html#获取方式-2

atian25 avatar May 27 '17 01:05 atian25

@atian25 要升级成Node.js 7.6+才行吗?

xjchenhao avatar May 27 '17 01:05 xjchenhao

看你的 middleware 是哪一种风格,分别有不同的用法,文档那里不是有示例代码么

atian25 avatar May 27 '17 01:05 atian25

哦哦 懂了 谢谢🙏

xjchenhao avatar May 27 '17 02:05 xjchenhao