Vue 编码规范
基本约束
单个JS / Vue 文章代码不能超过 800行
800行禁止提交非必要 console.log
console.logESLint 规则必须通过才能提交
ESLint 规则必须通过才能提交变量 / 方法名有拼写错误需修改
能使用 Lodash 的方法不要自己写
const newValue = cloneDeep(oldValue)const newValue = { ...oldValue }只添加必要注释
// Check if an incoming prop key is a declared emit event listener.
// e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
// both considered matched listeners.
export function isEmitListener(comp: Component, key: string): boolean { ... }命名规范
class / type 名需要大写开头
方法 / 对象 要采用驼峰命名
如对应关系未获得广泛认可,禁止使用缩写
数值 / 字符等基础数据类型常量,使用全大写
注意对象层级结构,不要重复描述
Vue
Prop
非必填需提供默认值
定义应该尽量详细
Composition API
目录结构
所有的 hook 函数必须使用 use 开头
use 开头使用 CompositionAPI ref 开头的变量要使用 $ 开头
ref 变量返回时需要去掉 $ 开头
Vuex
禁止在页面中使用 $store API
读取 store 数据,需要通过 getter
getter分发Action 需要使用 mapActions
页面中禁止直接调用 Mutation
禁止在 Getters 中操作 Store 数据、dispatch & commit
Last updated