使用电子app.getPath('home');时出错 [英] Error when using electron `app.getPath('home');`

查看:224
本文介绍了使用电子app.getPath('home');时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在电子应用程序中使用的脚本中包含以下代码:

I have the following code within a script I am using within my electron app:

window.$ = window.jQuery = require('jquery');
const {
   app
} = require('electron');
$(document).ready(function() {
   let home = app.getPath('home');
   let homePathTemplate = document.getElementById('home');
    homePathTemplate.innerHTML(home);
});

哪个看起来应该可以工作,但是收到以下错误:

Which looks as though it should work however receive the following error:

Uncaught TypeError: Cannot read property 'getPath' of undefined

有任何快速解决方案的想法吗?

Any ideas for a quick fix?


编辑1

Edit 1

具有以下内容

const app = require('electron');

与上述功能相同,我收到以下错误:

And the same function as above I receive the following error:

Uncaught TypeError: app.getPath is not a function at HTMLDocument.


推荐答案

window.$ = window.jQuery = require('jquery');
const { remote } = require('electron');
const app = remote.app;

$(document).ready(function() {
   let home = app.getPath('home');
   console.log(home)
   let homePathTemplate = document.getElementById('home');
   homePathTemplate.innerHTML(home);
});

并确保在以下情况下启用 nodeIntegration 您正在主流程中创建 BrowserWindow

And make sure you are enabling nodeIntegration when you are creating BrowserWindow in main process

这篇关于使用电子app.getPath('home');时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆