当前位置:网站首页>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
边栏推荐
- 并发之CAS
- Overall design and implementation of Kubernetes-based microservice project
- Hbuilder 学习使用中的一些记录
- 全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
- 线程之Happens-before规则
- ts/js function pass parameter with function writing
- 使用稀疏 4D 卷积对 3D LiDAR 数据中的运动对象进行后退分割(IROS 2022)
- 正则表达式replaceAll()方法具有什么功能呢?
- The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
- 开源一夏|OpenHarmony如何查询设备类型(eTS)
猜你喜欢
Overall design and implementation of Kubernetes-based microservice project
为什么我推荐使用智能化async?
茄子科技CEO仇俊:以用户为中心,做用户真正需要的产品
IDEA执行Test操作导致数据插入时出现了重复数据
Xcode10的打包方式distribute app和启动项目报错以及Xcode 打包本地ipa包安装到手机上
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
shell脚本实例
Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood
seata源码解析:事务状态及全局锁的存储
施一公:科学需要想象,想象来自阅读
随机推荐
Creo 9.0 基准特征:基准点
代码审计—PHP
Xcode 12 ld: symbol(s) not found for architecture armv64
PAT Grade B-B1020 Mooncake(25)
Why do I recommend using smart async?
PAT乙级-B1021 个位数统计(15)
基于 Kubernetes 的微服务项目整体设计与实现
Happens-before rules for threads
在colab里怎样读取google drive数据
上海控安技术成果入选市经信委《2021年上海市网络安全产业创新攻关成果目录》
Thinking and summary of the efficiency of IT R&D/development process specification
CCVR eases heterogeneous federated learning based on classifier calibration
新白娘子传奇系列
How to realize the short press and long press detection of the button?
2022-08-01 Review the basic binary tree and operations
CCVR基于分类器校准缓解异构联邦学习
无题四
express hot-reload
leetcode refers to Offer 10- II. Frog jumping steps
无题十一