离子版本控制在浏览器平台中不起作用

ionic versioning not working in the browser platform

有没有办法读取适用于所有平台(android、ios 和网络)的 ionic 3 应用程序版本?

我试过 cordova-plugin-app-version

this.appVersion.getVersionNumber().then(response => {
    console.log('App version', response);
})

版本未在浏览器中显示。

您可以像这样阅读 package.json 的版本:

 const environment = {
          VERSION: require('../../../package.json').version
    };

我的方法是在 index.html 中声明一个全局变量 app_version ,每次我制作新版本时都会更新它。然后,无论您在哪个平台,您的应用程序中的任何地方都可以访问该全局变量。

在你的 index.html 中:

<script>
var app_version = require('../package.json').version;
</script>

然后在需要使用它的任何页面或组件中只需在 @Component(...) 声明之前添加:

declare const app_version;

app_version 现在可以分配给组件 属性 并在必要时显示;