egg 项目实战(二)初始Egg.js中的路由

1.创建 product 控制器

app/controller/product.js

const Controller = require('egg').Controller;

class ProductController extends Controller {
    async index() {
        /**
         * ctx 主要用来存储用户请求的信息
         * 每次请求时都会实例化
         */
        const { ctx } = this;
        ctx.body = 'product';
    }
}

module.exports = ProductController;

2.添加路由

posted @ 2020-02-27 12:00  每天都要进步一点点  阅读(796)  评论(0)    收藏  举报