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
In a complex table structure, some cells span mul...
Table of contents 0. The kernel tree that comes w...
Table of contents What are immutable values? Why ...
The image can be easily pushed directly to the Do...
MySQL foreign key constraint (FOREIGN KEY) is a s...
NAT In this way, the virtual machine's networ...
Frequently asked questions Access denied for user...
A simple license plate input component (vue) for ...
1. InnoDB storage engine must be used It has bett...
After watching this, I guarantee that you have ha...
Preface When introducing defineProperty before, I...
This article uses an example to illustrate the us...
1. Docker imports local images Sometimes we copy ...
When programmers do TypeScript/JavaScript develop...
First we need to know the self-calling of the fun...