UI -- Vue3

本文介绍了如何在Vue3中创建和使用名为sl-button的UI组件,包括组件结构、安装方法、全局注册以及在VitePress文档中的应用。
摘要由CSDN通过智能技术生成

Vue3 模板

Vue3 UI

  • package.json同级
  • components/slButton/element.vue
<template>
    <div class="dddiv"><span>测试321</span></div>
</template>

<script setup>
    defineOptions({
    name: "sl-button"
});
</script>

<style scoped>
    .dddiv span{
    color: red;
}
</style>  
  • components/slButton/index.js
import element from "./element.vue";
element.install = (app) => app.component(element.name, element);
export default element;
  • components/function.js
export const ceshi = ()=>{
    console.log('123')
}
  • components/index.js
import slButton from "./slButton/index"
import {ceshi} from "./function"

const components = [slButton];

const install = (app, opts = {}) => {
    components.forEach((component) => {
        app.use(component);
    });
    app.config.globalProperties.$ceshi = ceshi;
};

const Sl = {
    install,
    slButton
};

export { slButton, install };
export default Sl;

使用

  • main.js
import Sl from '../components/index'
// 打包使用需要引入css
createApp(App).use(SL).mount('#app');


<sl-button></sl-button>

import { getCurrentInstance } from "vue";
const { appContext } = getCurrentInstance();
appContext.config.globalProperties.$ceshi();

UI 文档

npm i vitepress -D
  • package.json
"scripts": {
    "docs:dev": "vitepress dev docs",
    "docs:build": "vitepress build docs",
    "docs:serve": "vitepress serve docs"
  }
  • package.json 同级
  • docs 创建

docs 目录结构

  • .vitepress
    • theme
      • index.js
    • config.js
  • component
    • slbutton.md
  • get-started
    • index.md
  • guid
    • index.md
  • img
    • logo.ico
    • s.png
  • install
    • index.md
  • index.md

.vitepress

  • theme/index.js
import DefaultTheme from "vitepress/theme";
import Sll from "../../../components/index";
// 引入打包之后的需要css

export default {
    ...DefaultTheme,
    enhanceApp: async ({ app }) => {
        app.use(Sll);
    },
};

component

  • slbutton.md
  • \ 需去掉
# button


<ClientOnly>
<sl-button></sl-button>
</ClientOnly>

::: details 显示代码

\```html
<sl-button></sl-button>
\```

:::

get-started

  • index.md
---
title: 快速上手
---

## 安装

请参考 [安装](../install/) 章节


## 单个引入
 
## 全局引入
 

guid

  • index.md
---
title: UI
---

# UI


 

👀 介绍

- 本 UI 框架是基于 Vue3 实现的。

📌 项目特点

- UI

🔮 视觉稿

- UI

🚲 为什么叫   UI

- UI

install

  • index.md
  • \ 需去掉
---
title: 安装
---

# 安装

推荐安装  xxx@版本

\```bash
npm install xxx@版本
\```

或

\```bash
yarn add xxx@版本
\```

index.md

---
layout: home


features:
- title: 简易好学
  icon: ⚡
  details: 基于 VUE3
- title: Vue 驱动
  icon: 🖖
  details: 享受 Vue 的开发体验,实践最流行的技术。
- title: s-ui
  icon: 🛠️
  details: s-ui
---

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值