当前位置:网站首页>egg框架使用(一)
egg框架使用(一)
2022-08-05 09:29:00 【前端小草籽】
目录
egg初始化步骤
1.去到项目文件夹 taobao 里面 运行 cmd
2.输入 npm init egg --type=simple egg框架初始化
得到下面的文件:

3.还是会差一部分模块:输入 npm i 下载
结果为:

4.下载完毕 npm run dev 启动服务器

分析:egg框架的默认端口号为:7001 . 也可以输入本机真正的ip:192.168.x.xx:7001
5.浏览器输入 http://127.0.0.1:7001/ 或者 http://192.168.0.105/ 会出现

这是框架给用户提前注册好的网址

分析:当用户输入的pathname为 / 或者不输入pathname,就会运行 controller文件夹里面的home文件中的index函数

如果pathname 随便输入:会出现

注意点:前后端交互,是用JSON数据,即使后端返回给前端的数据 样式上是一个对象 或者其它样式数据,但实际上是JSON数据,未来前端是用axios进行网络请求,会把JSON数据 '{"name":"你好","age":"20"}'转换为对象:{name:'你好',age:20}

egg文件夹认识

分析:public文件夹里面的所有静态文件都有自己的网址,就不用 router.get 注册

egg约定规则
1 app/router.js:用于配置URL路由规则;
2 app/controller/ :用于解析用户的输入,处理后返回相应的结果;
3 app/service/: 用于编写业务逻辑层;
4 app/public/: 用于放置静态资源;(静态托管)
5 config/config.{env}.js: 用于编写配置文件;
6 config/plugin.js 用于配置需要加载的插件;
egg官方网址
https://eggjs.org
边栏推荐
- Excuse me, guys, is it impossible to synchronize two databases in real time using Flink SQL CDC?
- IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
- 21 Days of Deep Learning - Convolutional Neural Networks (CNN): Clothing Image Classification (Day 3)
- Assembly language (8) x86 inline assembly
- thinkPHP5 realizes clicks (data increment/decrement)
- leetcode 剑指 Offer 10- I. 斐波那契数列
- 上海控安技术成果入选市经信委《2021年上海市网络安全产业创新攻关成果目录》
- Rotation of the displayed value on the button
- Embedded practice ---- based on RT1170 transplant memtester to do SDRAM test (25)
- The Seven Weapons of Programmers
猜你喜欢

全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了

Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g

leetcode: 529. 扫雷游戏

ECCV 2022 Oral 视频实例分割新SOTA:SeqFormer&IDOL及CVPR 2022 视频实例分割竞赛冠军方案...

2022.8.3

sql server中 两表查询 平均数 分组

Thinking and summary of the efficiency of IT R&D/development process specification

express hot-reload

IDEA执行Test操作导致数据插入时出现了重复数据

How to realize the short press and long press detection of the button?
随机推荐
阿里云存储的数据库是怎么自动加快加载速度的呢www.cxsdkt.cn怎么设置案例?
CPU的亲缘性affinity
全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
为什么sys_class 里显示的很多表的 RELTABLESPACE 值为 0 ?
Xcode 12 ld: symbol(s) not found for architecture armv64
自定义过滤器和拦截器实现ThreadLocal线程封闭
Undefined symbols for architecture arm64解决方案
16 kinds of fragrant rice recipes
Creo 9.0 基准特征:基准坐标系
2022/8/4 考试总结
链表中的数字相加----链表专题
【ASM】字节码操作 方法的初始化 Frame
明天去订票,准备回家咯~~
【zeno】为zeno增加子模块/新节点的最小化的例子
微服务 技术栈
什么是CRM决策分析管理?
CCVR基于分类器校准缓解异构联邦学习
随时牵手 不要随意分手[转帖]
leetcode: 529. 扫雷游戏
Going to book tickets tomorrow, ready to go home~~