美文网首页
egg使用总结

egg使用总结

作者: webjiacheng | 来源:发表于2018-04-26 10:41 被阅读0次
  • 获取参数
    获取get的参数:ctx.query
    获取post的参数:ctx.request.body
  • 启动和停止指定进程
    在package.json中指定参数
"scripts": {
    "start": "egg-scripts start --port=${端口号} --daemon --title=${进程名称}",
    "stop": "egg-scripts stop --title=${进程名称}"
}

-RESTful 风格的 URL 定义

// app/router.js
module.exports = app => {
  const { router, controller } = app;
  router.resources('posts', '/api/posts', controller.posts);
  router.resources('users', '/api/v1/users', controller.v1.users); // app/controller/v1/users.js
};

上面代码就在 /posts 路径上部署了一组 CRUD 路径结构,对应的 Controller 为 app/controller/posts.js 接下来, 你只需要在 posts.js 里面实现对应的函数就可以了。


image.png

相关文章

网友评论

      本文标题:egg使用总结

      本文链接:https://www.haomeiwen.com/subject/wpdplftx.html