[Electron]总结:如何创建Electron+Element Plus的项目

我将结合官网手册与AI问到的信息,直接给出步骤,与命令。

一、准备环境

首先在C盘Users,你的登录的账号名文件夹下,编辑**.npmrc**文件。添加镜像地址。

如果使用了yarn,则是.yarnrc。可以全部都配置。

bash 复制代码
npm install -g yarn
bash 复制代码
registry=https://registry.npmmirror.com
ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
bash 复制代码
npm config set registry https://registry.npm.taobao.org

二、创建Element项目

并使用Electron Forge的 Vite template.

bash 复制代码
npm init electron-app@latest my-vue-app -- --template=vite

三、添加依赖

bash 复制代码
npm install vue
bash 复制代码
npm install --save-dev @vitejs/plugin-vue

四、配置页面

根目录/index.html

html 复制代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World!</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/renderer.js"></script>
  </body>
</html>

src/App.vue

html 复制代码
<template>
  <h1>💖 Hello World!</h1>
  <p>Welcome to your Electron application.</p>
</template>

<script setup>
console.log('👋 This message is being logged by "App.vue", included via Vite');
</script>

src/renderer.js

javascript 复制代码
import { createApp } from 'vue';
import App from './App.vue';

createApp(App).mount('#app');

根目录/ vite.renderer.config.mjs

javascript 复制代码
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config
export default defineConfig({
  plugins: [vue()]
});

至此我们创建了基于Vue3的Electron项目。

2-4步骤,参考自官网How to create an Electron app with Vue and Electron Forge

五、安装Element-plus

bash 复制代码
npm install element-plus

六、配置页面

src/renderer.js

javascript 复制代码
// src/renderer.js
import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';

const app = createApp(App);
app.use(ElementPlus);
app.mount('#app');

src/App.vue

html 复制代码
<!-- src/App.vue -->
<template>
  <div id="app">
    <h1>Hello, Electron Forge with Vue 3 and Element Plus!</h1>
    <el-button type="primary">Primary Button</el-button>
  </div>
</template>

<script>
export default {
  name: 'App'
};
</script>

致此完成。启动

相关推荐
麦麦麦当劳大王8 小时前
【油猴脚本】Boss直聘 岗位职责复制
开发语言·前端·javascript
小lu飞9 小时前
2026小红书小工具怎么制作:纯前端 ZIP 打包、沙箱限制与笔记挂载流程
前端·笔记·ai·ai编程
只睡四小时9 小时前
Three.js Sub-tick:漏判 60.7%→0
开发语言·javascript·性能优化·ecmascript·游戏开发·three.js·碰撞检测
smallcelebration10 小时前
151 从0开始搭建后端项目
前端·firefox
wangruofeng10 小时前
手机和电脑传文件,除了微信还有 LocalSend
前端
excel10 小时前
基于 GPT 的自动发布文章接口方案:从一句话或一张图片生成并发布内容
前端·javascript·后端
其实防守也摸鱼12 小时前
个人学习 Pwn 思路:从基础到漏洞利用的进阶路径
大数据·前端·人工智能·chrome·算法·安全·网络安全
朱涛的自习室13 小时前
212 个需求、22 万行代码:Agent 接管开源项目的 19 天
android·前端·人工智能
aZhe的全栈知识分享13 小时前
AI 还原 Figma 效果总达不到预期?先别急着让它写代码
前端·后端·面试
review4454313 小时前
Codex Hooks 入门实战:生命周期事件、matcher 与5分钟跑通一个钩子
前端·agent·vibecoding