/m1/index.js

  1. const Router = require("koa-router");
  2. const router = new Router();
  3. const MembersModel = require("../models/Members");
  4. // 查询数据库
  5. router.get("/m1",async ctx=>{
  6. var data = await MembersModel.find({});
  7. await ctx.render("index",{arr:data});
  8. })
  9. module.exports = router;

index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
  9. <style>
  10. img {
  11. width: 40px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <h1>数据展示</h1>
  17. <a style="float: right;" type="button" class="btn btn-warning" href="/m1/logout">退出登录</a>
  18. <a href="/m1/add" type="button" class="btn btn-success">添加成员</a>
  19. <table class="table table-bordered table-hover">
  20. <thead>
  21. <tr>
  22. <th>编号</th>
  23. <th>姓名</th>
  24. <th>年龄</th>
  25. <th>头像</th>
  26. <th>点赞</th>
  27. <th>是否交好友</th>
  28. <th>操作</th>
  29. </tr>
  30. </thead>
  31. <tbody>
  32. {{each arr}}
  33. <tr>
  34. <td>{{$value._id}}</td>
  35. <td>{{$value.name}}</td>
  36. <td>{{$value.age}}</td>
  37. <td><img src="{{$value.avatar}}" alt=""></td>
  38. <td>
  39. <img src="{{$value.like?'dianzan-after.png':'dianzan.png'}}" alt="">
  40. </td>
  41. <td>
  42. {{if $value.friend}}
  43. <p>是</p>
  44. {{else}}
  45. <p>否</p>
  46. {{/if}}
  47. </td>
  48. <td>
  49. <!-- a标签只支持get方式 -->
  50. <a href="/m1/doDelete?id={{@ $value._id}}" type="button" class="btn btn-danger">删除</a>
  51. <a href="/edit?id={{@ $value._id}}" type="button" class="btn btn-warning">修改</a>
  52. </td>
  53. </tr>
  54. {{/each}}
  55. </tbody>
  56. </table>
  57. </body>
  58. </html>