1. Add in package.json"main": "electron.js", In "scripts": { add: "package": "electron-packager ./ appName --overwrite" In "dependencies": { add: "electron-share-memory": "^1.0.1", "node-gyp-build": "^4.3.0", "vue-photo-preview": "^1.1.3", In "devDependencies": { add: "electron": "^15.3.1", "electron-packager": "^15.4.0", 2.vue.config.jsIn devServer: {modify: // open: true, (It was not commented out before, comment it out now) In proxy: {modify '/api': { target: "electron-renderer", (only this place is changed, before it was target: 'http://localhost',) changeOrigin: true, pathRewrite: { '^/api': '' } } 3. Add to main.js:import preview from 'vue-photo-preview' import 'vue-photo-preview/dist/skin.css' Vue.use(preview) // Solve electron error process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'TRUE' 4. Add electron.js at the same level as vue.config.js// Modules to control application life and create native browser window const {app, BrowserWindow} = require('electron') const path = require('path') function createWindow () { // Create the browser window. const mainWindow = new BrowserWindow({ width: 1889, height: 1000, webPreferences: { preload: path.join(__dirname, 'preload.js') } }) // and load the index.html of the app. // mainWindow.loadFile('./dist/index.html') mainWindow.loadURL('http://172.16.1.155:7890/xjbd') // Open the DevTools. mainWindow.webContents.openDevTools() } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(() => { createWindow() app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. 5. Add preload.js at the same level as vue.config.js// All of the Node.js APIs are available in the preload process. // It has the same sandbox as a Chrome extension. window.addEventListener('DOMContentLoaded', () => { const replaceText = (selector, text) => { const element = document.getElementById(selector) if (element) element.innerText = text } for (const type of ['chrome', 'node', 'electron']) { replaceText(`${type}-version`, process.versions[type]) } }) 6. Package the project first
Then run
This is the end of this article about adding electron to the vue project. For more relevant vue adding electron content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: MySQL slow query and query reconstruction method record
Table of contents 1. Introduction 2. The first me...
1. Browser rendering mode and doctype Some web pa...
Table of contents Preface cause Phenomenon why? A...
What is nGrinder? nGrinder is a platform for stre...
1. On a networked machine, use the default centos...
How to change the MySQL database directory locati...
Application Scenario Taking the background manage...
1 Keep the rpm package downloaded when yum instal...
Please open the test page in a mainstream browser...
This article uses an example to describe how to c...
Table of contents 1. React Basic Usage Notable Fe...
When checking the slow query, I found that the ti...
Vue first screen performance optimization compone...
background Some time ago, our project team was he...
Table of contents Optimization of if judgment 1. ...