在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue 如何使用Electron 模塊

vue 如何使用Electron 模塊

官方demo是

const BrowserWindow = require('electron').remote.BrowserWindow
const newWindowBtn = document.getElementById('frameless-window')

const path = require('path')

newWindowBtn.addEventListener('click', function (event) {
  const modalPath = path.join('file://', __dirname, '../../sections/windows/modal.html')
  let win = new BrowserWindow({ frame: false })
  win.on('close', function () { win = null })
  win.loadURL(modalPath)
  win.show()
})

但是實(shí)際怎么加呢? 我把const轉(zhuǎn)為import from的方式導(dǎo)入到需要的頁面提示fs模塊找不到,webpack配置跳過檢測但是Electron會報(bào)錯(cuò)。

import BrowserWindow from 'BrowserWindow'
import path  from 'path'
methods: {
    click() {
        const BrowserWindow = BrowserWindow.remote.BrowserWindow
        const modalPath = path.join('file://', __dirname,'../../sections/windows/modal.html')
        let win = new BrowserWindow({ frame: false })
        win.on('close', function () { win = null })
        win.loadURL(modalPath)
        win.show()
    }
}

就是添加一個(gè)關(guān)閉窗口的按鈕

回答
編輯回答
編輯回答
離人歸

window.require 在vue里面顯示undefined 我沒有用electron-vue 請問這個(gè)怎么處理

2017年10月14日 17:25
編輯回答
假灑脫

在需要的vue頁面中添加

  if (window.require) {
    var ipc = window.require('electron').ipcRenderer
  }

方法里添加

if (window.require) {
    ipc.send('close');
  }

原因:直接require會導(dǎo)致提示找不到fs模塊,需要使用window.require,但是在Chrome環(huán)境中提示window.require not function所以需要做一次判斷
在Electron的main.js里添加

const ipc = require('electron').ipcMain
ipc.on('close', e => mainWindow.close());
2017年12月16日 03:53