1-1 加载页面
在controller 文件夹 新建 doDelete.js
'use strict';
const Controller = require('egg').Controller;
const { ObjectId } = require("mongodb")
class DoDeleteController extends Controller {
async index() {
const { ctx } = this;
var { _id } = ctx.query;
var db = this.app.mongodb;
const collection = await db.collection('member');
//找到对应id并删除
var dele = await collection.deleteOne({ _id: ObjectId(_id) });
console.log(dele);
//跳转回home页面
await ctx.redirect("/home")
}
}
module.exports = DoDeleteController;
对应路由
router.get('/detail', controller.detail.index);
通过 home.html 传值