超详细!!!electron-vite-vue开发桌面应用之引入UI组件库element-plus(四)

ops/2024/10/18 16:48:13/

云风网
云风笔记
云风知识库

一、安装element-plus以及图标库依赖

npm install element-plus --save
npm install @element-plus/icons-vue
npm i -D unplugin-icons

二、vite按需引入插件

npm install -D unplugin-vue-components unplugin-auto-import

unplugin-vue-components是一个用于Vue.js的插件,它允许你导入Vue组件,而不需要在你的代码中显式地导入它们。这个插件可以让你按需导入组件,从而减少初始加载大小。

unplugin-auto-import是一个用于Vue.js的插件,它可以自动导入Vue.js的相关API,如Vue自身,Vue的RFC(响应式),Composition API,以及其他一些常用的Vue功能。

三、vite.config.ts文件配置引用element-plus

import { defineConfig } from 'vite'
import path from 'node:path'
import electron from 'vite-plugin-electron/simple'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'//自动导入相关api
import Components from 'unplugin-vue-components/vite'//按需导入组件
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
// https://vitejs.dev/config/
export default defineConfig({plugins: [AutoImport({resolvers: [// 自动导入elementPlus组件ElementPlusResolver(),// 自动导入图标组件 IconsResolver({prefix: 'Icon',})],dts: path.resolve(__dirname, 'types/auto-imports.d.ts')}),Components({resolvers: [ElementPlusResolver(),// 自动注册图标组件IconsResolver({enabledCollections: ['ep'],})],dts: path.resolve(__dirname, 'types/components.d.ts')}),//图标的导入配置Icons({autoInstall: true,}),vue(),electron({main: {// Shortcut of `build.lib.entry`.entry: 'electron/main.ts',onstart(args) {args.reload()// args.startup()}},preload: {// Shortcut of `build.rollupOptions.input`.// Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.input: path.join(__dirname, 'electron/preload.ts'),},// Ployfill the Electron and Node.js API for Renderer process.// If you want use Node.js in Renderer process, the `nodeIntegration` needs to be enabled in the Main process.// See 👉 https://github.com/electron-vite/vite-plugin-electron-rendererrenderer: process.env.NODE_ENV === 'test'// https://github.com/electron-vite/vite-plugin-electron-renderer/issues/78#issuecomment-2053600808? undefined: {},}),],
})

四、element-plus应用到页面

 <el-button type="success" @click="count++">count is {{ count }}</el-button><el-icon><IEpPlus/></el-icon><i-ep-delete />

页面渲染效果如下

在这里插入图片描述

注意事项

Iconify 图标结构由三部分组成:{prefix}-{collection}-{icon}
prefix:icon的前缀,默认值为’i’,可设置成false,如果设置成false,那么组件使用就变成
collection: 默认是iconify
icon: 图标集中对应的图标名字
collection对应的是 enabledCollections配置,默认是iconify上的所有图标。这里设置的是[‘ep’],表示的是Iconify 中的 element-plus 的图标,也可以设置mdi、ant-design,它会自动根据名称在package.json下载安装对应的图标集
Icons()表示会自动安装@iconify-json/ep的依赖,设置为true,他就会自动安装iconify 图标。

四、补充说明插件unplugin-vue-components和unplugin-auto-import

1、安装依赖运行后,根目录自动生成两个ts声明文件
components.d.ts
/* eslint-disable */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}/* prettier-ignore */
declare module 'vue' {export interface GlobalComponents {ElButton: typeof import('element-plus/es')['ElButton']HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']}
}
auto-imports.d.ts
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import
export {}
declare global {}

这里直接注释app.vue中组件的引入代码

<script setup lang="ts">
// import HelloWorld from './components/HelloWorld.vue'
</script>

再次运行项目,组件正常显示,因为已经插件自动引入,无需手动页面路径引用

在这里插入图片描述

2、对于d.ts文件进行模块化管理

在这里插入图片描述

vite.config.ts文件进行自动导入路径配置

在这里插入图片描述
再次运行项目,组件正常显示


http://www.ppmy.cn/ops/94349.html

相关文章

控制台返回<empty string>是什么意思

您输入的是一个空字符串&#xff0c;这表示没有任何字符或内容。空字符串在编程和数据处理中很常见&#xff0c;用于表示缺失的文本、未定义的值或需要后续填充的数据字段。在不同的编程语言中&#xff0c;空字符串的表示方法可能略有不同&#xff0c;但大多数语言都支持这一概…

生物液氮罐操作不当导致的常见问题及解决方案

生物液氮罐广泛应用于冷冻保存生物样本&#xff0c;如细胞、组织和胚胎。由于其操作要求严格&#xff0c;液氮罐操作不当可能会导致一系列问题&#xff0c;影响样本的质量和安全。常见的问题包括液氮的过度蒸发、液氮温度过高、样本污染等&#xff0c;这些问题都需要及时解决以…

vscode 快速生成vue 格式

1.用快捷Ctrl Shift P唤出控制台 输入“Snippets”并选择 Snippets: Configure User Snippets 2.输入vue&#xff0c;选中vue.json vs code自动生成vue.json文件 3.在 vue.json 中添加模板 {"Print to console": {"prefix": "vue2","b…

多线程与信号

消息处理 #include <sys/types.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <stdio.h> #include <string.h> #include <unistd.h> #includ…

8.12LVS

一&#xff0e;LVS概述 1.什么是lvs&#xff1a; lvs是一个实现负载均衡集群开源软件项目&#xff0c;lvs逻辑上可以分为调度层&#xff0c;server集群层和共享层 2.特点&#xff1a;免费&#xff0c;开源&#xff0c;四层负载均衡 3.Lvs工作原理 4.lvs调度算法: 静态调度…

IO流用到的设计模式

IO流用到的设计模式 装饰器&#xff08;Decorator&#xff09;模式 可以在不改变原有对象的情况下拓展其功能。例如&#xff0c;可以通过 BufferedInputStream&#xff08;字节缓冲输入流&#xff09;来增强 FileInputStream 的功能。适配器&#xff08;Adapter Pattern&#…

2024年,除了幕布思维导图外三款好用的工具推荐!!

工作当中我们的成果都是靠着各种的工作汇报来体现的&#xff0c;其中就包括了excel、ppt和思维导图这类的形式了&#xff0c;是不是就需要给上级做这类的汇报体现工作的价值&#xff0c;而使用好用的一些工具可以让我们的工作事半功倍起来&#xff0c;所以今天整理了幕布思维导…

注册数据查询工具

注册数据查询工具&#xff1a;ICANN Lookup