remote 模板在13版本后禁用了,至于我为什么用它。 是因为一个功能的原因。多个子窗口可以进行对应的操作事件后单独关闭当前的某一个子窗口。
1:先进行下载 npm/yarn install --save @electron/remote
2:需要单独引入remote模块 。–因为我是子窗口使用 (引入的地方带有 // 1,2,3)
import { app, BrowserWindow, ipcRenderer, ipcMain, Menu, Tray } from "electron";
const remote = require("@electron/remote/main") //1
remote.initialize() //2
/ 子窗口
function childcrewindos() {
childWindow = new BrowserWindow({
width: 365,
height: 512,
useContentSize: true,
resizable: false, //窗口宽高禁止拉动
frame: false,
webPreferences: {
nodeIntegration: true, //在网页中集成Node
contextIsolation: false,
},
});
childWindow.on("closed", () => {
childWindow = null;
});
childWindow.show();
childWindow.loadURL(winURL + `#/childList`);
remote.enable(childWindow.webContents) //3
}
3:然后在子窗口页面中
methods 中
getCurrentWindow() {
return require('@electron/remote').getCurrentWindow();
},
然后在使用的地方进行调用 就可以进行关闭子窗口了。
this.getCurrentWindow().close()