如何在Nativescript Vue应用程序的两个默认页面中进行选择?

时间:2019-09-10 09:06:07

标签: nativescript-vue

我正在使用NativeScript 6.1.0和NativeScript-Vue 2.3.0构建应用程序。启动应用程序时,我想检测是否已设置用户ID,如果已设置,请转到帐户页面,否则请转到登录页面。我具有帐户页面和登录页面作为“帐户”和“登录”组件,并且有一个根组件。

到目前为止,我唯一可以实现此目的的方法是将根组件呈现为具有空页面的框架,并从已安装的挂钩中调用$ navigateTo。 除非将其包装为超时,否则该导航将无法正常工作,因此我得到了空白页面的提示。没有超时,导航将不起作用-没有错误,但仍停留在空白页面上。我怀疑没有伪页面也可以干净地完成此操作,但是我不知道该怎么做。

import Vue from 'nativescript-vue';
const appSettings = require("application-settings");
import Account from "./components/Account";
import Login from "./components/Login";

new Vue({

    mounted () {
        setTimeout(() => {
            let userId = parseInt(appSettings.getNumber("userId"));
            if (!isNaN(userId)) this.$navigateTo(Account);
            else this.$navigateTo(Login);
        }, 500);
    },

    template: `
        <Frame>
            <Page></Page>
        </Frame>`

}).$start();

0 个答案:

没有答案