‘use strict‘;
const { Controller } = require(‘egg‘);
class HomeController extends Controller{
async index() {
let str = ‘欢迎来到天天的世界!‘;
let arr = [{
name: ‘明明‘,
sex: ‘男‘,
age: ‘18‘
},{
name: ‘璇璇‘,
sex: ‘女‘,
age: ‘16‘
}];
await this.ctx.render(‘home‘, {
arr,
str
})
}
}
module.exports = HomeController;
<4>. 在 Html 中可以这样写
<body>
<div style="color: lightseagreen;">{{str}}</div>
<ol>
{% for item in arr %}
<li>
<p>{{item.name}}--{{item.sex}}--{{item.age}}</p>
</li>
{% endfor %}
</ol>
</body>