美文网首页
2.在egg中使用handelbars模版引擎

2.在egg中使用handelbars模版引擎

作者: 丸子_d7e2 | 来源:发表于2019-07-18 21:44 被阅读0次
1.安装   egg-view-handlebars
2.在config目录下的plugin,js中配置
  exports.handlebars = {
    enable: true,
    package: 'egg-view-handlebars',
  };
3.在config.default.js下配置
config.view = {
    root: [
      path.join(appInfo.baseDir, 'app/view'),
    ].join(','),
    defaultViewEngine: 'handlebars',
    defaultExtension: '.hbs',
    mapping: {
      '.hbs': 'handlebars',
    }
  };
4.在controller层使用handelbars渲染对应页面
class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }
  async news() {
    const { ctx } = this;
    let a={name:"andong"}
    await ctx.render('home.hbs',a);
  }
}

相关文章

网友评论

      本文标题:2.在egg中使用handelbars模版引擎

      本文链接:https://www.haomeiwen.com/subject/blgrlctx.html