Electron 没有通过 app.getVersion() 命令获取有效的版本数据

Electron does not get valid version data through the app.getVersion() command

我无法理解为什么我的应用无法获取正确的版本数据。

我已经在我的 package.json 中添加了版本行并且我使用 vue-electron 所以我在这个更新组件中编写我的代码。

<template>
  <Window title='Program Updater'>
    <div class='wrap' id='currentAppVersion'>
      Current App Version : {{currentAppVersion}}
    </div>
    <div class='wrap' id='checkNewVersion'>
      Latest App Version : {{latestAppVersion}}
    </div>
    <button class='login' @click="$emit(updateCheck ? 'exist' : 'latest')">{{updateCheck ? 'Update' : 'latest version!'}}</button>
  </Window>
</template>

我在区域中添加了此代码以从 package.json 获取版本数据。但是它显示 'electron package' 版本,我不知道为什么它与.

有关


[我的一部分index.vue]

const electron = require('electron')
const app = electron.app || electron.remote.app

  data () {
    return {
      currentAppVersion: app && app.getVersion(),
      latestAppVersion: 'Not yet Developed'
    }
  }

一开始以为是electron版本太低导致的错误。但是我读了 3.1.X 文档有 app.getVersion() 方法,我不知道如何修复它。

有人说我可以使用 'process.env.npm_package_version' 命令,实际上,它有效。但在生产模式下它 return 没有数据。

[已解决]

通过这段代码,我解决了这个问题。但是在开发模式下它不起作用但是在生产模式下它运行良好

const electron = require('electron')
const app = electron.app || electron.remote.app

  data () {
    return {
      currentAppVersion: app && app.getVersion(),
      latestAppVersion: 'Not yet Developed'
    }
  }