首页 > 解决方案 > How do I switch which Vue component I display in my app depending on whether it's build in Cordova or Electron?

问题描述

I have a Vue.js app. For mobile apps I build the app with Cordova and for Desktop clients I build it with Electron. In some cases I want my application to react differently depending on whether it's build for Cordova or Electron.

If I want to show the CordovaStartPage-component with Cordova and ElectronStartPage with Electron, how do I have to change:

export const routerOptions: RouterOptions = {
    routes: [
        {
            path: "/startpage",
            component: StartPage
        }
    ]
}

标签: cordovavue.jselectron

解决方案


要检测电子,我只需将调用包装在 if 检查中:

window && window.process && window.process.type

还有:

process.versions['electron']

希望这可以帮助。


推荐阅读