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

致此完成。启动

相关推荐
Smile_Gently2 小时前
前端:最简单封装nmp插件(组件)过程。
前端·javascript·vue.js·elementui·vue
nihui1237 小时前
Uniapp 实现顶部标签页切换功能?
javascript·vue.js·uni-app
luckycoke8 小时前
小程序立体轮播
前端·css·小程序
一 乐8 小时前
高校体育场管理系统系统|体育场管理系统小程序设计与实现(源码+数据库+文档)
前端·javascript·数据库·spring boot·高校体育馆系统
懒羊羊我小弟8 小时前
常用Webpack Loader汇总介绍
前端·webpack·node.js
shengmeshi9 小时前
vue3项目img标签动态设置src,提示:ReferenceError: require is not defined
javascript·vue.js·ecmascript
BillKu9 小时前
vue3中<el-table-column>状态的显示
javascript·vue.js·elementui
祈澈菇凉9 小时前
ES6模块的异步加载是如何实现的?
前端·javascript·es6
我爱学习_zwj9 小时前
4.从零开始学会Vue--{{组件通信}}
前端·javascript·vue.js·笔记·前端框架
顾比魁9 小时前
XSS盲打:当攻击者“盲狙”管理员
前端·网络安全·xss