环境搭建
npx create-electron-app@latest my-vue-app --template= vite
npm install vue
npm install --save-dev @vitejs/plugin-vue
修改以下文件
index.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
< 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
import { createApp } from 'vue' ;
import App from './App.vue' ;
createApp ( App) . mount ( '#app' ) ;
vite.renderer.config.mjs
import { defineConfig } from 'vite' ;
import vue from '@vitejs/plugin-vue' ;
export default defineConfig ( {
plugins: [ vue ( ) ]
} ) ;
启动项目
npm run start