[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>

致此完成。启动

相关推荐
雨中飘荡的记忆1 小时前
淘宝搜不到的东西,能不能去全世界找?一个程序员的创业尝试
前端·设计
kyriewen1 小时前
我让 4 位 AI 面试官打分,同一个我差了 40 分
前端·面试·程序员
htzyl2062 小时前
Vue3中watch的deep默认值:reactive与ref为什么相反
前端·vue.js
用户112936112193 小时前
没写样式为什么还找我要 wxss?uni-app 这个 ENOENT 坑多数人误判了
前端·微信小程序·uni-app
用户553665935263 小时前
从零做一个全国山峰与线路库:山野抽签的初衷、架构与踩坑
前端
夕水3 小时前
用 SolidJS 复刻 DeepSeek Chat —— 顺便把 ew-solid-ui 拷打了一遍
前端·javascript
qq_274475153 小时前
第 17 篇:ES6 语法速览:解构赋值、展开运算符、模板字符串、对象简写
前端·ecmascript·es6
2603_965896624 小时前
JavaScript 原型与原型链,读懂 JS 对象的底层机制
开发语言·javascript·原型模式
凯程序猿1号5 小时前
Web墨卡托EPSG3857瓦片行列号XYZ与经纬度双向换算及地面分辨率推导
前端·电脑
qq_274475155 小时前
第 21 篇:Proxy 代理与 Reflect:数据劫持基础,Vue 响应式底层原理前置
前端·javascript·vue.js