需要配置路由。src/router/index.js
{
path: "/selectMode",
name: "selectMode",
component: () => import("/@/view/selectMode/index.vue"),
},
src/**.vue
import { ipcRenderer } from "electron";
const openNewTab = () => {
let params = {
url: "/selectMode", // 路由path
};
ipcRender.send("openNewTab", params);
};
electron/index.ts
let nweTab
// 打开新窗口
ipcMain.on("openNewTab", async (event, arg) => {
newTab = new BrowserWindow({
width: 1400,
height: 800,
webPreferences: {
// preload: path.join(__dirname, "preload.js"),
nodeIntegration: true,
contextIsolation: false,
webSecurity: false, // 禁用同源策略,允许跨域
},
});
if (process.env.VITE_DEV_SERVER_URL) {
newTab.loadURL(url + "#" + arg.url);
// newTab.loadURL(`http://localhost:3000/#/file_preview`)
newTab.webContents.openDevTools();
} else {
newTab.loadFile("dist/index.html", {
hash: arg.url
});
// newTab.loadFile("dist/index.html", {
hash: "/file_preview"
})
newTab.webContents.openDevTools();
}
});