问题
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?
Edit 1
With the following
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.
回答1:
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);
});
And make sure you are enabling nodeIntegration
when you are creating BrowserWindow
in main process
来源:https://stackoverflow.com/questions/60444303/error-when-using-electron-app-getpathhome