而且我的设置页打开会白屏闪一下 相关问题录制请看我bilibili
https://www.bilibili.com/video/BV1GdvDBDEeq/
const router = createRouter({
history: createWebHashHistory(),
linkActiveClass: 'link-active',
routes: routes,
})
import {BrowserWindow, app, dialog} from "electron";
import path from "path";
import eventEmitter from "@/main/event";
import {t} from "@/main/i18n";
const window = async () => {
let mainWindow = new BrowserWindow({
width: 1300,
height: 803,
minWidth: 1300,
minHeight: 803,
title: app.getName(),
// frame:false,
titleBarStyle: "hidden",
minimizable: true,
maximizable: true,
// transparency: true,
// backgroundColor: "#00000000",
vibrancy: "under-window",
visualEffectState: "followWindow",
// alwaysOnTop: true,
fullscreenable: true,
// opacity:0.9,
fullscreen: false,
// show: false,
closable: true,
autoHideMenuBar: true,
webPreferences: {
webgl: true,
// devTools: process.env.NODE_ENV === 'development',
nodeIntegration: true,
contextIsolation: true,
webSecurity: true,
sandbox: true,
backgroundThrottling: false,
preload: path.join(__dirname, 'preload.js'),
defaultFontFamily: 'sansSerif'
}
});
mainWindow["name"] = "main";
// mainWindow.setFullScreenable(true)
// mainWindow.setFullScreen(false)
// 使用相对路径加载 asar 文件中的 HTML
// const appPath = app.getAppPath();
// const indexPath = path.join(appPath, 'app.asar', 'index.html');
// mainWindow.loadURL(`file://${indexPath}`);
if (process.env.NODE_ENV === 'development') {
await mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
await mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
}
eventEmitter.on('messageFromVM', (message) => {
try {
if (mainWindow && mainWindow.webContents && !mainWindow.webContents.isDestroyed()) {
mainWindow.webContents.send(`task:console`, message)
}
} catch (_) {}
})
// 退出确认:点击主窗口的关闭按钮时先弹框确认
let isQuittingApp = false;
app.on('before-quit', () => { isQuittingApp = true; });
mainWindow.on('close', (e) => {
if (!isQuittingApp) {
e.preventDefault();
const result = dialog.showMessageBoxSync(mainWindow, {
type: 'question',
title: t('message.exitConfirmTitle'),
message: t('message.exitConfirmMessage'),
detail: t('message.exitConfirmDetail'),
buttons: [t('message.exitConfirmCancel'), t('message.exitConfirmExit')],
defaultId: 1,
cancelId: 0,
});
if (result === 1) {
// 先关闭所有子窗口(使用 destroy 避免重复 close 事件)
BrowserWindow.getAllWindows().forEach((win) => {
if (win !== mainWindow && !win.isDestroyed()) {
win.destroy();
}
});
isQuittingApp = true;
app.quit();
}
// 用户取消则不做处理
}
});
return mainWindow;
};
export default window
根据你描述的 Electron-Vue 动态路由打包后白屏问题及代码片段,以下是解决方案和优化建议:
component: () => import(...)) 在 Electron 生产环境中可能因路径问题导致组件未加载。webPreferences 配置(如 sandbox: true)可能限制路由功能。在 路由配置文件 中,修改动态导入语法为绝对路径:
// 原写法(可能失效)
component: () => import('./views/DynamicPage.vue')
// 改为绝对路径
component: () => import(/* webpackMode: "eager" */ path.resolve(__dirname, 'src/views/DynamicPage.vue'))
关键配置:在 vue.config.js 中添加 Webpack 路径别名:
// vue.config.js
const path = require('path');
module.exports = {
configureWebpack: {
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
}
}
}
在 窗口初始化代码 中:
const mainWindow = new BrowserWindow({
// ...其他配置
show: false, // 先隐藏窗口
backgroundColor: '#2e2c29' // 设置背景色与应用主题一致
});
// 页面加载完成后显示窗口
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
webPreferences: {
// ...
sandbox: false, // 关闭沙箱模式(解决部分路由限制)
webSecurity: false, // 允许加载本地资源(生产环境需谨慎)
nodeIntegration: true, // 确保为 true
}
在 router/index.js 中指定基础路径:
const router = createRouter({
history: createWebHashHistory(process.env.NODE_ENV === 'production' ? './' : '/'),
// ...
})
dist 目录中的 index.html 正确引用了 JS/CSS 文件,静态资源路径应为相对路径(如 ./js/app.js)。预加载策略
在 preload.js 中验证 Node.js 模块是否可用:
// preload.js
window.electron = {
require: require
};调试生产环境
通过以下命令启动打包后的应用,查看控制台报错:
electron --inspect=5858 ./dist在 Chrome 中访问 chrome://inspect 调试。
// main.js 窗口修改
const mainWindow = new BrowserWindow({
// ...
show: false,
backgroundColor: '#2e2c29',
webPreferences: {
// ...
sandbox: false, // 动态路由需关闭沙箱
}
});
// 添加窗口就绪事件
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// 路由文件修改
const router = createRouter({
history: createWebHashHistory(process.env.NODE_ENV === 'production' ? './' : '/'),
// ...
})
若仍存在问题,请检查 Vue Devtools 是否有报错(开发环境通过 mainWindow.webContents.openDevTools() 开启)。
访问路由空白无效果无报错;dev开发模式没问题,只存在build后通过服务打开页面存在问题。 通过调试问题出在beforeEach代码: 以上代码改成下面就可以访问了: 路由使用 createWebHashHistory 方式 开发模式没问题,应该排除代码问题吧?
最近在使用vue-admin-template开发后台管理系统,遇到动态路由刷新出现页面白屏问题 用户登录时通过角色获取角色路由并动态加载到router对象 在App.vue 中将保存于vuex中的路由信息刷新前存入到sessionStorage中,刷新后取出并重新加载路由; 重置路由方法 全局路由守卫 角色路由直接编写在JS文件中 出现问题正常登录能够进行路由跳转但是点击浏览器刷新出现页面白屏,
项目用的 vue3+vite,包管理器 pnpm,执行 pnpm build。 生成的js为啥把路由劝返回出来了。被检测存在系统路径信息泄露,怎么解决呢 vite配置文件build部分: build生成的js文件:
将vue发到tauri上npm run tauri dev启动后的后台api的请求地址是http://ip:port/xxx 为啥npm run tauri build打包后变成了http://tauri.localhost:port/xxx tauri.conf.json
主要内容:安装,简单实例,HTML 代码,JavaScript 代码,<router-link> 相关属性本章节我们将为大家介绍 Vue 路由。 Vue 路由允许我们通过不同的 URL 访问不同的内容。 通过 Vue 可以实现多视图的单页 Web 应用(single page web application,SPA)。 Vue.js 路由需要载入 vue-router 库 中文文档地址:vue-router 文档。 安装 1、直接下载 / CDN NPM 推荐使用淘宝镜像: 简单实例 Vue.j
router.getRoutes()数据如下。 页面报错No match found for location with path "/a" 路由跳转:空白页面。
想通过v-router路由守卫和vuex实现一个动态路由,路由数据由后端返回,求一个demo参考下。
Vite + Vue3 + Electron 打包后静态资源路径错误 图片 src 如果是动态拼接的话,路径指向会出现问题 第一个路径不正确:file:///G:/vite.svg 第二个路径为:file:///G:/vite-electron/release/win-unpacked/resources/app.asar/dist/vite.svg 还有这种字体文件导入也会出现问题,类似上面直接