跳到内容
SCRM DOC

组件开发相关文档导航

前端组件创建于2025-03-22更新于 2025-03-22

组件开发文档

核心技术

文档说明
[[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 库:

<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)

组件结构

<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>

相关链接

页面信息›
已优化是

本页目录