转载:https://github.com/pablohpsilva/vuejs-component-style-guide/blob/master/README-CN.md
- 一个组件专注解决一个单一问题
- vue组件命名前缀,连字符(-),简短
- 组件表达式简单化,复杂使用 method或computed替代
- 组件prop原子化(是使用原始类型)
- 验证组件的props,为了 保证你的组件永远是可用的(防御式编程)
- 将this赋值给component变量(es6)
- 组件结构化-其一(name; extends; props, data 和 computed; components; watch 和 methods; 5. lifecycle methods 等)。
- 组件事件命名,使用连字符,对应组件外的一组意外操作,以动词或名词结尾
- 避免this.$parent,访问组件之外的上下文违反了基于模块开发的第一原则。
- 谨慎使用this.$refs,!!!
- 使用组件名作为样式作用域空间,???
- 提供组件API文档,!!
- 提供组件demo,添加index.html文件作为组件的demo示例
- 对组件文件进行代码校验-使用elint-plugin-html插件
- 只在需要时创建组件,!!!
- 尽可能使用mixins(Mixins 封装可重用的代码)