开发规范
# vue
| 对象 | 命名规范 | 示例 |
|---|---|---|
| 项目名称 | kebab-case | my-vue-project |
| 目录名称 | kebab-case / 复数形式 | components/、composables/ |
| 组件文件(SFC) | PascalCase 或 kebab-case(统一) | UserCard.vue 或 user-card.vue |
| 组件 name 属性 | PascalCase | 'UserCard' |
| 基础组件前缀 | Base/App/V + PascalCase | BaseButton.vue |
| 单例组件前缀 | The + PascalCase | TheHeader.vue |
| 页面文件 | PascalCase | HomePage.vue |
| 变量/函数 | camelCase | userName、fetchData |
| 常量 | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| 布尔变量 | is/has/can + camelCase | isLoading |
| 组合式函数 | use + camelCase | useAuth |
| 接口/类型 | PascalCase | UserProfile |
| Props 接口 | PascalCase + Props 后缀 | UserCardProps |
| 枚举名称 | PascalCase | UserStatus |
| 枚举成员 | UPPER_SNAKE_CASE | ACTIVE |
| 路由名称 | camelCase | userProfile |
| 路由路径 | kebab-case | /user-profile |
| Props 声明(JS) | camelCase | greetingText |
| Props 模板使用 | kebab-case | greeting-text |
| 事件名 | kebab-case | @update-value |
| 事件处理函数 | camelCase | handleUpdate |
# php
目录小写,文件 PascalCase,类 = 文件,数据库 snake_case,代码 camelCase
# 命名规范
| 类型 | 命名规则 | 示例 | 备注 |
|---|---|---|---|
| 类名 | PascalCase | UserService | 与文件名一致 |
| 方法名 | camelCase | getUserInfo() | — |
| 变量名 | camelCase | $orderId | — |
| 布尔变量 | is/has/can + 名词 | $isLogin | 推荐 |
| 常量 | UPPER_CASE | MAX_RETRY | — |
| 命名空间 | 目录映射 | app\service\order | 必须 |
| 接口 | 后缀 Interface | CacheInterface | — |
| 抽象类 | 前缀 Abstract | AbstractController | — |
| 枚举 | 后缀 Enum | StatusEnum | — |
# 目录&文件名
| 类型 | 目录 | 文件名 | 示例 |
|---|---|---|---|
| 控制器 | app/controller | XxxController.php | UserController.php |
| 业务层 | app/service | XxxService.php | PayService.php |
| 模型 | app/model | Xxx.php/ XxxModel.php | Order.php |
| 中间件 | app/middleware | XxxMiddleware.php | AuthMiddleware.php |
| 异常 | app/exception | XxxException.php | BusinessException.php |
| 工具类 | app/utils | XxxUtil.php | DateUtil.php |
| 配置 | config/ | xxx.php | database.php |
| 路由 | route/ | web.php/ api.php | — |
上次更新: 2026/05/14, 10:42:32