# 02. 组件开发
URL: /%E6%96%87%E6%A1%A3/04.%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/01.%20%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/02.%20%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF/00.%20%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E5%AF%BC%E8%88%AA

组件开发相关文档导航


# 组件开发文档

## 核心技术

| 文档 | 说明 |
|------|------|
| [[01. 前端组件 - 组件创建指南]] | 组件开发基础指南 |
| [[02. Pinia 状态管理]] | Pinia 状态管理使用指南 |
| [[03. Vue Router 路由]] | Vue Router 4 路由配置 |
| [[04. 微前端 Wujie]] | Wujie 微前端框架集成 |
| [[05. VXE Table 表格]] | VXE Table 高级表格 |
| [[06. ECharts 图表]] | ECharts 图表组件 |
| [[10. HTTP 请求]] | HTTP 请求封装使用 |

## 基础组件

项目使用 **Ant Design Vue 4.2** 作为主 UI 库：

```vue
<template>
  <a-button type="primary">按钮</a-button>
  <a-input v-model:value="value" />
  <a-select v-model:value="selectValue">
    <a-select-option value="1">选项1</a-select-option>
  </a-select>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const value = ref('');
const selectValue = ref(undefined);
</script>
```

## 组件规范

### 命名规范

- **组件文件**: PascalCase（如 `UserList.vue`）
- **组件注册**: PascalCase（如 `<UserList />`）
- **组件属性**: camelCase（如 `showTitle`）
- **事件名**: kebab-case（如 `@update-value`）

### 组件结构

```vue
<template>
  <!-- 模板 -->
</template>

<script setup lang="ts">
// 1. 导入
import { ref, computed } from 'vue';
import type { PropType } from 'vue';

// 2. Props 定义
interface Props {
  title: string;
  data?: Record<string, any>;
}
const props = withDefaults(defineProps<Props>(), {
  data: () => ({}),
});

// 3. Emits 定义
interface Emits {
  (e: 'update:modelValue', value: string): void;
  (e: 'change', value: string): void;
}
const emit = defineEmits<Emits>();

// 4. 响应式状态
const count = ref(0);

// 5. 计算属性
const doubleCount = computed(() => count.value * 2);

// 6. 方法
function increment() {
  count.value++;
  emit('change', count.value);
}

// 6. 暴露给父组件的方法
defineExpose({
  increment,
});
</script>

<style scoped lang="less">
/* 样式 */
</style>
```

## 相关链接

- [Ant Design Vue 文档](https://antdv.com/)
- [Vue 3 文档](https://cn.vuejs.org/)
- [VXE Table 文档](https://vxetable.cn/)
