node.js - koa-static出现generators will been removed in v3?
怪我咯
怪我咯 2017-04-17 15:22:30
0
2
615

koa deprecated Support for generators will been removed in v3. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/...,求解?

怪我咯
怪我咯

走同样的路,发现不同的人生

Antworte allen (2)
Ty80

找到方法了
npm install koa-convert --save

import convert from 'koa-convert'

app.use(convert(require('koa-static')(__dirname + '/public')));

    PHPzhong

    看这里!

    是你仍然在用传统的 1.x 里的生成器语法才会出现这条提示,是 koa 善意的提醒啦,避免以后升到 v3 你的代码就瘫痪了!所以如果你仍然继续想使用生成器语法的话就借助 co 模块吧!

    官方的栗子:

    app.use(co.wrap(function *(ctx, next) { const start = new Date(); yield next(); const ms = new Date() - start; console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); }));

    PS:既然你都用 v2 了,为啥不async/await用起来呢!

      Neueste Downloads
      Mehr>
      Web-Effekte
      Quellcode der Website
      Website-Materialien
      Frontend-Vorlage
      Über uns Haftungsausschluss Sitemap
      Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!