使用koa2的koa-ejs的推荐代码是什么? [英] What's the recommend code for koa-ejs using koa2?
本文介绍了使用koa2的koa-ejs的推荐代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我计划在koa2中使用ejs,我的代码就像blelow:
I planed use ejs in koa2, my codes were like as blelow:
render(app, {
root: path.join(__dirname, 'views-ejs'),
layout: 'layout',
viewExt: 'ejs',
cache: false,
debug: true
});
app.use(function *() {
yield this.render('index',{
title: 'koa2 title',
viewClass: 'landing',
targetAuthLevel:'',
authorizationLevel:'6',
ngController: 'landingController'
});
});
但是,我收到以下警告,您能告诉我推荐什么代码吗?请.
But, I get the below warning, would you tell me what's codes are recommended? please.
koa弃用的版本v3中将删除对发电机的支持.见 有关如何转换旧的中间件的示例的文档 https://github.com/koajs/koa/tree /v2.x#old-signature-middleware-v1x
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/tree/v2.x#old-signature-middleware-v1x
推荐答案
每个自述文件:
Koa 2的解决方法
npm install co --save
然后...
import co from 'co';
import render from 'koa-ejs';
render(app, options);
app.context.render = co.wrap(app.context.render);
app.use(async (ctx, next) => {
await ctx.render(view, locals);
});
这篇关于使用koa2的koa-ejs的推荐代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文