Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

electron+vue为什么本地运行正常,但是打包后,运行空白还报主进程和渲染进程错误

问题原因:electron+vue为什么本地运行正常,但是打包后,运行空白还报主进程和渲染进程错误

本人调试:本地运行,主进程和渲染进程都没问题

相关代码

var { app, Menu, Tray, ipcMain, BrowserWindow,dialog } = require('electron')
const Store = require("electron-store");
const request = require('request');
const fs = require('fs')
const store = new Store();
let appIcon = null
var path = require('path')
// 获取当前窗口对象 BrowserWindow.getFocusedWindow();
var mainWindow = BrowserWindow.getFocusedWindow()
appIcon = new Tray(path.join(__dirname, '../../static/image/music.ico'))

打包后appIcon这个路径提示错误,但是本地运行没有问题

ipcMain.on("download", (evt, item) => {
  console.log('item',item)
  let pathsave = store.get("savepath");
  if (pathsave != undefined) {
    downloadFile(item.url, item.title, pathsave, function() {
      mainWindow.webContents.send("downsuccess", item);
    });
  } else {
    dialog.showOpenDialog(mainWindow, {
        properties: ["openDirectory"],
      }).then((res) => {
        store.set("savepath", res.filePaths[0]);
        downloadFile(item.url, item.title, res.filePaths[0], function() {
          mainWindow.webContents.send("downsuccess", item);
        });
      }).catch((err) => {
        console.log(err);
      });
  }
});

这边提示path路径有问题

期待哪位大神可以看看


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. 确保这个资源有被打包进去
  2. 确保打包后的路径是否正确

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...