惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
G
Google Developers Blog
腾讯CDC
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
博客园_首页
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
A
About on SuperTechFans
Y
Y Combinator Blog
L
LangChain Blog
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

zodream梦想开源/个人编程日记

文件解析笔记-zodream梦想开源/个人编程日记 密码本开发笔记之读写与保存-zodream梦想开源/个人编程日记 SkiaSharp 把 pixel byte[] 转成 SKBitmap-zodream梦想开源/个人编程日记 nas 使用 Docker 安装 gogs-zodream梦想开源/个人编程日记 复制 android 手机中的文件到电脑-zodream梦想开源/个人编程日记 周报:寻找优质的周刊-zodream梦想开源/个人编程日记 开发日志:对Markdown的代码块新增引用来源支持-zodream梦想开源/个人编程日记 周报:怎么写技术类的教程文章-zodream梦想开源/个人编程日记 css display:flex 布局尺寸超出问题-zodream梦想开源/个人编程日记 周报:SEO优化的思考-zodream梦想开源/个人编程日记 Edge 浏览器不适用 Edge Image Viewer 打开图片 -zodream梦想开源/个人编程日记 SEO 学习笔记(一) 内容来源-zodream梦想开源/个人编程日记 PHP 实现双因素身份认证(2FA)-zodream梦想开源/个人编程日记 WPF MVVM 获取List 多选数据-zodream梦想开源/个人编程日记 Burp Suite 抓包-zodream梦想开源/个人编程日记 使用 indexnow 注意事项-zodream梦想开源/个人编程日记 Godot 使用字体图标 例如: Iconfont、FontAwesome-zodream梦想开源/个人编程日记 angular 15 对指定页面进行访问限制-zodream梦想开源/个人编程日记 CSS 使用 column-count 实现瀑布流出现内容分割的解决办法-zodream梦想开源/个人编程日记 input 确认按键事件在手机端不生效-zodream梦想开源/个人编程日记 C# 使用socket 进行通讯-zodream梦想开源/个人编程日记 Maui开发中Windows应用开启管理员权限-zodream梦想开源/个人编程日记 Maui 中自定义控件-zodream梦想开源/个人编程日记 angular 14 使用 ng-template 实现tree 结构显示-zodream梦想开源/个人编程日记 c# 动态安装和卸载dll-zodream梦想开源/个人编程日记 慎用 CompositionTarget.Rendering-zodream梦想开源/个人编程日记 c# 重写 c++ 程序笔记:数据初始化-zodream梦想开源/个人编程日记 源码编译 aseprite-zodream梦想开源/个人编程日记 记录一下字符串分隔split各语言之间的不同-zodream梦想开源/个人编程日记 c# Gzip解码无头内容-zodream梦想开源/个人编程日记
【Vue Shop】代码优化-zodream梦想开源/个人编程日记
zodream · 2019-10-10 · via zodream梦想开源/个人编程日记

代码优化

  1. 变量写法统一
  2. 空格控制
  3. 类型转化规范

由于使用了 typescript 编写,所以引入了 TSLint 作为代码规范检查工具,在编写过程中并没有太注重代码的规范,导致每次编译的代码提示都刷刷的好几页。

在基本功能完成后进行代码优化工作。

  1. 类型转化提示,例如 parseInt 第二个参数必填 10 表示转化为十进制。页面获取传值 this.$route.querythis.$route.params 返回多个类型的值,如果需要string 则使用 as string 做类型转化声明,实际在js 代码中不做处理。如果需要 number 则需要使用 parseInt(this.$route.query.a as string, 10) 进行转化
  2. 变量统一使用驼峰写法,默认的 ts 规范也是这么规范的,当然也可以改,反正我是习惯用驼峰写法
  3. 字符串和引入文件路径使用单引号,当然这也可以改,vscode 默认生成的引用可以在设置里面设置或在 tsconfig.json 中配置
  4. 清除空白行中的空格
  5. 补全 , 和 ;
  6. 匿名函数如果只有一个参数可以不用括号和声明类型,多个参数必须括号和声明类型
  7. 一行文字不超过120个,超过截断换行
  8. 同意代码风格,页面都使用类的写法
  9. 类的所有成员包括属性,方法都加上 publicprivate 修饰符
  10. 变量声明,尽量使用 const

转载请保留原文链接: https://zodream.cn/blog/id/81.html