vue3组件编码规范
time: 2022-04-01 19:12:40
author: heyunjiang
规范条例
组件命名
- 使用大驼峰
- 单例组件使用 The 开头,比如
TheHeader
- 与父组件耦合的子组件,命名应当以父组件名作为前缀
-
多单词
- 没有内容的组件使用,保持组件自闭合,比如
<MyComponent />
- template 中组件使用优先大驼峰,其次 kebab-case
- jsx 中必须使用大驼峰
- 组件名称全写,不缩写
- 声明 props 使用小驼峰,在 template 绑定使用时用 kebab-case
- 多个 attribute 应该换行
- sfc 组件内部顺序:style 放最后,script 和 template 全局都保持一致
元素 attribute 顺序:
- is
- v-for
- v-if, v-else, v-show, v-cloak
- v-pre, v-once
- id
- ref, key
- v-model
- 其他 attribute
- v-on, @ 绑定事件
- v-html, v-text
参考文章
vue3 风格指南