@yh-kit/vue-materials
@yh-kit/vue-materials
Vue3 物料库,封装了基于 Vue 3 + TypeScript 的常用布局组件与 UI 组件,开箱即用。
组件一览
| 组件 | 说明 | 使用文档 |
|---|---|---|
| AdminLayout | 管理员端(后台)布局:logo、菜单栏、头部、tab 区、内容区、底部 | docs/use/layout/AdminLayout.MD |
| BlankLayout | 空白布局:内置 keep-alive 缓存的 router-view | docs/use/layout/BlankLayout.MD |
| PortalLayout | 门户布局:头部、banner、内容区、底部、左右侧边栏、返回顶部 | docs/use/layout/PortalLayout.MD |
| MtIcon | 图标组件:兼容 iconfont(symbol 方式)与本地 SVG 图片 | docs/use/ui/MtIcon.MD |
| MtButton / MtTest | 通用 UI 组件(示例) | - |
安装
pnpm install @yh-kit/vue-materials
# or
npm install @yh-kit/vue-materials
# or
yarn add @yh-kit/vue-materials
import { AdminLayout } from '@yh-kit/vue-materials'
使用文档
各组件的详细使用文档位于 docs/use/ 目录:
| 组件 | 包内文档路径 |
|---|---|
| AdminLayout | node_modules/@yh-kit/vue-materials/docs/use/layout/AdminLayout.MD |
| BlankLayout | node_modules/@yh-kit/vue-materials/docs/use/layout/BlankLayout.MD |
| PortalLayout | node_modules/@yh-kit/vue-materials/docs/use/layout/PortalLayout.MD |
| MtIcon | node_modules/@yh-kit/vue-materials/docs/use/ui/MtIcon.MD |
# 安装本包后,直接查看组件使用文档(以 MtIcon 为例)
cat node_modules/@yh-kit/vue-materials/docs/use/ui/MtIcon.MD
各组件文档顶部提供「返回总览」入口,可与本页双向跳转。
使用组件
按需自动导入组件
需要安装 unplugin-vue-components 插件,用于按需自动导入组件。
然后在 vite.config.ts 中配置插件:
import { defineConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
export default defineConfig({
plugins: [
Components({
// 配置你的物料库作为自定义组件库
resolvers: [
(name: string) => {
// 如果组件名以 Mt 开头,从物料库中导入
if (name.startsWith("Mt") || name.endsWith("Layout")) {
return {
name,
from: "../libs"
};
}
}
]
})
],
})
页面使用组件
<template>
<AdminLayout />
<BlankLayout />
<mt-button />
<mt-test />
<mt-icon icon-name="icon-copy" />
</template>
全局使用 app.component 注册组件
在 main.ts 中注册组件
import { createApp } from 'vue'
import App from './App.vue'
import { AdminLayout, BlankLayout, MtButton, MtTest, MtIcon } from '@yh-kit/vue-materials'
const app = createApp(App)
app.component("AdminLayout", AdminLayout);
app.component("BlankLayout", BlankLayout);
app.component("MtButton", MtButton);
app.component("MtTest", MtTest);
app.component("MtIcon", MtIcon);
app.mount('#app')
在 App.vue 中使用组件
<template>
<AdminLayout />
<BlankLayout />
<mt-button />
<mt-test />
<mt-icon icon-name="icon-copy" />
</template>
参考
仓库
Gitee 仓库(monorepo,本包位于 packages/vue3-materials)
Related Packages
Version History
| Version | Released | License |
|---|---|---|
| 1.4.0 | ||
| 1.3.2 | ||
| 1.3.1 | ||
| 1.3.0 | ||
| 1.2.0 | ||
| 1.1.1 | ||
| 1.1.0 | ||
| 1.0.5 | ||
| 1.0.4 | ||
| 1.0.3 | ||
| 1.0.2 | ||
| 1.0.1 | ||
| 0.0.1 |