loadUrl is not working in electron

现象

I tried to run the index.js with following lines, it worked

1
2
3
4
5
6
7
8
const electron = require("electron")
const app = electron.app
const BrowserWindow = electron.BrowserWindow
var mainWindow = null

app.on('ready', function () {
mainWindow = new BrowserWindow({width: 800, height: 600})
})

but when i tried to add this line,

1
mainWindow.loadUrl('file://${ __dirname}/index.html')

it return an error typeError:mainWindow.loadUrl is not a function

解决

1
loadUrl() was renamed to loadURL() a while back.