欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue項目中添加electron的詳細代碼

 更新時間:2021年11月18日 11:02:39   作者:(ღ星辰ღ)  
這篇文章通過實例代碼給大家介紹了vue項目中添加electron的方法,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧

1.在package.json中添加

 "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",

2.vue.config.js

在devServer: {修改:

// open: true,(之前是沒有注釋掉的,現(xiàn)在把他注釋掉)

在proxy: {修改

 '/api': {
        target: "electron-renderer",(只改了這個地方,之前是 target: 'http://localhost',)
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }

3.main.js添加:

import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
Vue.use(preview)
// 解決electron 報錯
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'TRUE'

4.在vue.config.js同級添加electron.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.在vue.config.js同級添加preload.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.先把項目打包

 npm run dev

然后在運行

 npm run package

請?zhí)砑訄D片描述

請?zhí)砑訄D片描述

到此這篇關(guān)于vue項目中添加electron的文章就介紹到這了,更多相關(guān)vue添加electron內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用vue中的v-for遍歷二維數(shù)組的方法

    使用vue中的v-for遍歷二維數(shù)組的方法

    下面小編就為大家分享一篇使用vue中的v-for遍歷二維數(shù)組的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • 使用vue-antDesign menu頁面方式(添加面包屑跳轉(zhuǎn))

    使用vue-antDesign menu頁面方式(添加面包屑跳轉(zhuǎn))

    這篇文章主要介紹了使用vue-antDesign menu頁面方式(添加面包屑跳轉(zhuǎn)),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 使用vue3指令封裝一個圖片預(yù)覽功能

    使用vue3指令封裝一個圖片預(yù)覽功能

    這篇文章主要為大家詳細介紹了如何使用?vue3?指令封裝一個后臺管理系統(tǒng)圖片預(yù)覽功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • Vue SPA 如何解決瀏覽器緩存問題

    Vue SPA 如何解決瀏覽器緩存問題

    這篇文章主要介紹了Vue SPA 如何解決瀏覽器緩存問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • VUE的數(shù)據(jù)代理與事件詳解

    VUE的數(shù)據(jù)代理與事件詳解

    這篇文章主要為大家介紹了VUE的數(shù)據(jù)代理與事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • vant?toast?關(guān)閉棧溢出問題及解決

    vant?toast?關(guān)閉棧溢出問題及解決

    這篇文章主要介紹了vant?toast?關(guān)閉棧溢出問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • vue與vue-i18n結(jié)合實現(xiàn)后臺數(shù)據(jù)的多語言切換方法

    vue與vue-i18n結(jié)合實現(xiàn)后臺數(shù)據(jù)的多語言切換方法

    下面小編就為大家分享一篇vue與vue-i18n結(jié)合實現(xiàn)后臺數(shù)據(jù)的多語言切換方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • VUE實現(xiàn)注冊與登錄效果

    VUE實現(xiàn)注冊與登錄效果

    這篇文章主要為大家詳細介紹了VUE實現(xiàn)注冊與登錄效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue中的高德軌跡回放

    Vue中的高德軌跡回放

    這篇文章主要介紹了Vue中的高德軌跡回放問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • 詳解vue大文件視頻切片上傳的處理方法

    詳解vue大文件視頻切片上傳的處理方法

    前端上傳大文件、視頻的時候會出現(xiàn)超時、過大、很慢等情況,為了解決這一問題,跟后端配合做了一個切片的功能,接下來就詳細的給大家介紹一下vue大文件視頻切片上傳的處理方法,需要的朋友可以參考下
    2023-08-08

最新評論