Skip to content
frontend-dev logo

前端开发规范

frontend-dev

前端开发规范,包含 Vue 3 编码规范、UI 风格约束、TypeScript 规范等

SKILL.md

Full skill instructions

前端开发规范

参考来源: Vue 官方风格指南、Element Plus 最佳实践


UI 风格约束

严格禁止(常见 AI 风格)

  • ❌ 蓝紫色霓虹渐变、发光描边、玻璃拟态
  • ❌ 大面积渐变、过多装饰性几何图形
  • ❌ 赛博风、暗黑科技风、AI 风格 UI
  • ❌ UI 文案中使用 emoji

后台系统(默认风格)

要素要求
主题使用组件库默认主题
配色黑白灰为主 + 1 个主色点缀
动效克制,仅保留必要交互反馈

技术栈

层级Vue(首选)React(备选)
框架Vue 3 + TypeScriptReact 18 + TypeScript
构建ViteVite
路由Vue Router 4React Router 6
状态PiniaZustand
UI 库Element PlusAnt Design

Vue 编码规范

组件基础

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import type { User } from '@/​types'

// Props & Emits
const props = defineProps<{ userId: number }>()
const emit = defineEmits<{ (e: 'update', value: string): void }>()

// 响应式状态
const loading = ref(false)
const user = ref<User | null>(null)

// 计算属性
const displayName = computed(() => user.value?.name ?? '未知用户')

// 生命周期
onMounted(async () => { await fetchUser() })

// 方法
async function fetchUser() {
  loading.value = true
  try {
    user.value = await api.getUser(props.userId)
  } finally {
    loading.value = false
  }
}
</​script>

<template>
  <div class="user-card">
    <h3>{{ displayName }}</​h3>
  </​div>
</​template>

<style scoped>
.user-card { padding: 16px; }
</​style>

命名约定

类型约定示例
组件文件PascalCase.vueUserCard.vue
ComposablesuseXxx.tsuseAuth.ts
StoreuseXxxStore.tsuseUserStore.ts

状态管理(Pinia)

// stores/​user.ts
export const useUserStore = defineStore('user', () => {
  const user = ref<User | null>(null)
  const token = ref<string>('')

  const isLoggedIn = computed(() => !!token.value)

  async function login(username: string, password: string) {
    const res = await api.login(username, password)
    token.value = res.token
    user.value = res.user
  }

  return { user, token, isLoggedIn, login }
})

交互状态处理

必须处理的状态: loading、empty、error、disabled、submitting

<template>
  <el-skeleton v-if="loading" :rows="5" animated />
  <el-result v-else-if="error" icon="error" :title="error">
    <template #extra>
      <el-button @click="fetchData">重试</​el-button>
    </​template>
  </​el-result>
  <el-empty v-else-if="list.length === 0" description="暂无数据" />
  <template v-else>
    <!-- 正常内容 -->
  </​template>
</​template>

TypeScript 规范

// types/​user.ts
export interface User {
  id: number
  username: string
  role: 'admin' | 'user'
}

export interface ApiResponse<T = unknown> {
  code: number
  message: string
  data: T
}

性能优化

场景方案
大列表虚拟滚动
路由懒加载 () => import()
计算使用 computed 缓存
大数据使用 shallowRef
// 路由懒加载
const routes = [
  { path: '/​dashboard', component: () => import('@/​views/​Dashboard.vue') }
]

// 请求防抖
import { useDebounceFn } from '@vueuse/​core'
const debouncedSearch = useDebounceFn((keyword) => api.search(keyword), 300)

目录结构

src/
├── api/                 # API 请求
├── components/          # 通用组件
├── composables/         # 组合式函数
├── router/              # 路由配置
├── stores/              # Pinia stores
├── types/               # TypeScript 类型
├── utils/               # 工具函数
├── views/               # 页面组件
├── App.vue
└── main.ts

详细参考

完整规范见 references/​frontend-style.md,包含:

  • 完整 UI 风格约束
  • Vue 3 编码规范详解
  • Pinia 状态管理
  • API 请求封装
  • 性能优化详解

📋 本回复遵循:frontend-dev - [具体章节]

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View