【问题标题】:fs.existsSync is not a function when importing electron导入电子时 fs.existsSync 不是函数
【发布时间】:2020-01-23 07:49:37
【问题描述】:

我目前正在使用 Vue 和 Electron,并希望使用

重新启动应用程序
import { app } from 'electron';

export default {
  name: 'Home',
  methods: {
   restartApp() {
      app.relaunch()
      app.exit()
   }
  }
}

但是当我导入电子时,我得到了fs.existsSync is not a function

我也尝试过使用

const remote = require('electron');

import { app } from remote;

还有

const remote = window.require('electron')

回复我window.require is not a function

【问题讨论】:

    标签: javascript node.js vue.js electron


    【解决方案1】:

    您可以在创建主 BrowserWindow 时使用 webPreferences 中的 preload 参数。 在 main.js 中,

      mainWindow = new BrowserWindow({
        webPreferences: {
          nodeIntegration: false,
          preload: path.join(__dirname, 'preload.js')
        }
      })
    

    在 preload.js 中

        const remote = require("electron").remote;
        window.appQuit = function() {
          remote.app.exit(0);
        };
    

    【讨论】:

      猜你喜欢
      • 2020-11-25
      • 2019-05-19
      • 2020-08-12
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 2016-06-11
      • 2019-08-13
      相关资源
      最近更新 更多