Skip to content

安装与引入 ​

脚手架生成的项目已经把经过验证的 @kevairy/components 精确版本写入根 package.json,安装项目依赖时会自动从 npm registry 获取。

环境要求 ​

组件包的 peer dependencies 是:

  • Vue ^3.5.0;
  • Element Plus ^2.11.0。

按需导入组件 ​

vue
<script setup lang="ts">
  import { KvStatus } from '@kevairy/components'
  import '@kevairy/components/style.css'
</script>

<template>
  <KvStatus status="empty" />
</template>

样式需要显式导入一次。通常在应用入口导入 @kevairy/components/style.css,页面中只导入组件。

全局安装 ​

如果项目希望全局注册全部组件:

ts
import { createApp } from 'vue'
import KevairyComponents from '@kevairy/components'
import '@kevairy/components/style.css'

import App from './App.vue'

createApp(App).use(KevairyComponents).mount('#app')

按需导入更容易控制依赖范围;只有大量页面都使用组件库时再选择全局安装。

使用轻量入口 ​

不渲染 UI 的模块应从 /core 导入:

ts
import {
  sanitizeSearchParams,
  type PagedTableRequest,
  usePagedTable
} from '@kevairy/components/core'

/core 包含 composables、默认文案、公共类型和纯工具,不包含 UI 组件实现。