gpt4 book ai didi

javascript - 使用 Electron 时出错 `app.getPath(' home');`

转载 作者:行者123 更新时间:2023-11-28 16:46:57 50 4
gpt4 key购买 nike

我在 Electron 应用程序中使用的脚本中有以下代码:

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);
});

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

Uncaught TypeError: Cannot read property 'getPath' of undefined

有什么快速修复的想法吗?

Edit 1

具有以下内容

const app = require('electron');

与上面相同的函数我收到以下错误:

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);
});

并确保在主进程中创建 BrowserWindow 时启用 nodeIntegration

关于javascript - 使用 Electron 时出错 `app.getPath(' home');`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60444303/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com