1.安装 ejs
yarn add egg-view-ejs
2.修改配置
config/plugin.js
'use strict';
exports.ejs = {
enable: true,
package: 'egg-view-ejs'
};
config/config.default.js
config.view = {
mapping: {
'.html': 'ejs'
}
};
3.创建 html 文件
app/view/index.html
首页这是首页内容
id:
name:
4.传值
app/controller/home.js
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
const res = await ctx.service.product.index();
// ctx.body = res;
await ctx.render('index.html', {
res,
lists: ['a', 'b', 'c']
});
}
}
module.exports = HomeController;
5.效果
版权声明:本文为weixin_35441226原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。