Vue CLI Plugin Electron Builder 打包出现空白问题

使用yarn electron:serve 测试是正常的

打包后就异常了

首先修改路由模式

// vue-router 4.x版本
const router = createRouter({
  history: process.env.IS_ELECTRON ? createWebHashHistory(process.env.BASE_URL) : createWebHistory(process.env.BASE_URL),
  ...
});

/*
vue-router 4.0 以下版本
const router = createRouter({
  mode: process.env.IS_ELECTRON ? 'hash':'history',,
  ...
});
*/

然后在路由中首页面千万不要一异步引入,其他页面无所谓,可以使用异步方式引入

如果首页面想要异步引入的话。可以在app.vue 的created生命周期中跳转到 首页面

路由模式比较重要,生成环境不能使用histroy 虽然可以正常跳转,但是返回上一页就不知道跳哪去了

posted @ 2021-07-29 16:58  荣超  阅读(898)  评论(0编辑  收藏  举报