vue中如何添加electron,代码是什么
Admin 2022-07-07 群英技术资讯 562 次浏览
"main": "electron.js",
在 “scripts”: {添加:
"package": "electron-packager ./ appName --overwrite"
在"dependencies": {添加:
"electron-share-memory": "^1.0.1", "node-gyp-build": "^4.3.0", "vue-photo-preview": "^1.1.3",
在 “devDependencies”: {添加:
"electron": "^15.3.1", "electron-packager": "^15.4.0",
在devServer: {修改:
// open: true,(之前是没有注释掉的,现在把他注释掉)
在proxy: {修改
'/api': { target: "electron-renderer",(只改了这个地方,之前是 target: 'http://localhost',) changeOrigin: true, pathRewrite: { '^/api': '' } }
import preview from 'vue-photo-preview' import 'vue-photo-preview/dist/skin.css' Vue.use(preview) // 解决electron 报错 process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'TRUE'
// 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.
// 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]) } })
npm run dev
然后在运行
npm run package
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
JS表达式怎样写,JS操作符有哪些?一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
本文依旧给大家分享Javascript设计模式的内容,这篇主要介绍Javascript适配器模式,那么究竟Javascript适配器模式是什么呢?有什么用?如何实现?接下来我们一一了解清楚。
这篇文章主要为大家详细介绍了js实现简单图片切换,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
一、概述我们使用Vue.js一定要安装node.js吗?准确的说是使用vue-cli 搭建项目的时候需要nodejs。你也可以创建一个 .html 文件,然后通过如下方式引入 Vue,一样可以使用Vue。<!-
之前小编给大家介绍过JS宏任务与微任务的操作,今天我们继续来了解宏任务与微任务的内容,下文主要给大家讲一讲JavaScript宏任务与微任务的执行顺序,感兴趣的朋友就继续往下看吧。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008