remote模块使用出错,出现
Uncaught Error: @electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.
at IpcMainImpl.<anonymous>
依据提示,需要在main.js中添加一行require("@electron/remote/main").enable(webContents) 语句,但如果直接加,会显示webContents is not defined 错误。
不能直接加,webContents前要加上定义好的变量名,如下图,webContents应替换为 mainWindow.webContents。