/m1/index.js
const Router = require("koa-router");
const router = new Router();
const MembersModel = require("../models/Members");
// 查询数据库
router.get("/m1",async ctx=>{
var data = await MembersModel.find({});
await ctx.render("index",{arr:data});
})
module.exports = router;
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
img {
width: 40px;
}
</style>
</head>
<body>
<h1>数据展示</h1>
<a style="float: right;" type="button" class="btn btn-warning" href="/m1/logout">退出登录</a>
<a href="/m1/add" type="button" class="btn btn-success">添加成员</a>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>头像</th>
<th>点赞</th>
<th>是否交好友</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{{each arr}}
<tr>
<td>{{$value._id}}</td>
<td>{{$value.name}}</td>
<td>{{$value.age}}</td>
<td><img src="{{$value.avatar}}" alt=""></td>
<td>
<img src="{{$value.like?'dianzan-after.png':'dianzan.png'}}" alt="">
</td>
<td>
{{if $value.friend}}
<p>是</p>
{{else}}
<p>否</p>
{{/if}}
</td>
<td>
<!-- a标签只支持get方式 -->
<a href="/m1/doDelete?id={{@ $value._id}}" type="button" class="btn btn-danger">删除</a>
<a href="/edit?id={{@ $value._id}}" type="button" class="btn btn-warning">修改</a>
</td>
</tr>
{{/each}}
</tbody>
</table>
</body>
</html>