首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue3电子子组件/路线未显示

Vue3电子子组件/路线未显示
EN

Stack Overflow用户
提问于 2022-01-26 10:54:37
回答 1查看 306关注 0票数 0

因此,我一直在Vue3 (v3.2.25)和电子(v16.0.7)中工作。我一直在使用vue-router4 4在应用程序中的页面之间导航。我注意到,在开发过程中,我的应用程序运行良好。所有的东西都是它应该如何加载的,但是在生产过程中(当构建的时候),电子应用程序并不会呈现所有与路由器有关的东西,比如<router-view/>

作为第一个组件加载的App.vue文件:

代码语言:javascript
复制
<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
</script>

<template>
  <h1>bpe</h1>
  <router-view />
</template>

呈现bpe。但不是路由器

我的路由器:

代码语言:javascript
复制
import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
  Router,
  RouteRecordRaw,
} from "vue-router";

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    component: () => import("../pages/Login.vue"),
  },
  {
    path: "/dashboard/",
    component: () => import("../pages/dashboard/Home.vue"),
  },
];

const router: Router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;

我的vue main.ts

代码语言:javascript
复制
import { createApp } from "vue";
import App from "./App.vue";
import "./assets/tailwind.css";
import router from "./middleware/router";

const app = createApp(App);

app.use(router);

app.mount("#app");

electron.js:

代码语言:javascript
复制
const path = require("path");
const { app, BrowserWindow } = require("electron");
const log = require("electron-log");
const isDev = process.env.IS_DEV == "true" ? true : false;
const { autoUpdater } = require("electron-updater");
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
autoUpdater.setFeedURL({
  token: "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",
  owner: "Gezellligheid",
  repo: "bandi-app",
  provider: "github",
});

// import { autoUpdater } from "electron-updater";

function createWindow() {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,

    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      nodeIntegration: true,
    },
  });

  // and load the index.html of the app.
  // win.loadFile("index.html");
  mainWindow.loadURL(
    isDev
      ? "http://localhost:3000"
      : `file://${path.join(__dirname, "../dist/index.html")}`
  );
  // Open the DevTools.
  if (isDev) {
    mainWindow.webContents.openDevTools();
  }
  // if (!isDev) {
  //   mainWindow.removeMenu();
  // }
}
autoUpdater.on("checking-for-update", () => {
  console.log("Checking for update...");
});
autoUpdater.on("update-available", (info) => {
  console.log("Update available.", info);
});
autoUpdater.on("update-not-available", (info) => {
  console.log("Update not available.", info);
});
autoUpdater.on("error", (err) => {
  console.log("Error in auto-updater. " + err);
});
autoUpdater.on("download-progress", (progressObj) => {
  let log_message = "Download speed: " + progressObj.bytesPerSecond;
  log_message = log_message + " - Downloaded " + progressObj.percent + "%";
  log_message =
    log_message +
    " (" +
    progressObj.transferred +
    "/" +
    progressObj.total +
    ")";
  console.log(log_message);
});
autoUpdater.on("update-downloaded", (info) => {
  console.log("Update downloaded", info);
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
  autoUpdater.checkForUpdatesAndNotify();
  createWindow();
  app.on("activate", function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.

    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2022-03-07 13:24:58

我也有同样的问题。我找到了的解决方案,对我来说效果很好。尝试将路由器文件更改为:

代码语言:javascript
复制
import { createRouter, createWebHashHistory } from 'vue-router'

// ...

const router: Router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// ...

电子似乎只适用于WebHashHistory。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70862323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档