【问题标题】:NativeScript Vue Frame navigateTo not navigatingNativeScript Vue Frame navigateTo 不导航
【发布时间】:2019-04-19 01:10:03
【问题描述】:

[编辑] -> Playground Link

我正在使用 NativeScript 和 Vue 创建一个应用程序。加载后,我想显示一个登录页面,或者如果用户先前已登录,则导航到其他地方。 我的页面加载但没有导航到登录页面。这是在 IOS 模拟器中运行的。

<template>
    <Page>
        <RadSideDrawer ref="drawer" showOverNavigation="true">
            <StackLayout ~drawerContent backgroundColor="#ffffff">
                <Label class="drawer-header" text="Drawer"/>

                <Label class="drawer-item" text="Static 1"/>
                <Label class="drawer-item" text="Static 2"/>
                <Label class="drawer-item" text="Static 3"/>
            </StackLayout>
            <Frame ~mainContent> 
                <Page> <!-- test to see if mainContent navigates -->
                    <TextField class="input" hint="Email" keyboardType="email" autocorrect="false" autocapitalizationType="none" v-model="user.email"
                     returnKeyType="next" fontSize="18" />
               </Page>
            </Frame>
        </RadSideDrawer>
    </Page>
</template>

<script>
import homePage from './HomePage'
import loginPage from './LoginPage'

export default {
    data() {
        return {
            isLoggingIn: true,
            user: {
                email: "foo@foo.com",
                password: "foo",
                confirmPassword: "foo"
            }
        };
    },
    mounted() {
        this.user.email = "test@example.com", <!-- Change email to check mounted is called.  It is! -->
        this.$navigateTo(loginPage, { frame: "mainContent" } )
    }
};
</script>

我无法弄清楚我做错了什么,也无法从源头上解决问题。任何帮助/建议将不胜感激。

【问题讨论】:

    标签: nativescript nativescript-vue


    【解决方案1】:

    您尚未在RadSideDrawer 中为您的Frame 设置ID。

    为了让您的this.$navigateTo 代码正常工作,框架声明应该是

    ...
    <Frame id="mainContent" ~mainContent> 
    ...
    

    编辑:

    我已经更新了你的Playground sample

    • Page 只能是 Frame 的子代。所以我不得不更新你的LoginPage.vueHomePage.vue 来持有Page
    • 如果我没记错的话,RadSideDrawer 会在内部覆盖 mainContent 的 ref(虽然不确定),所以 id 在这里效果更好。
    • 当组件被挂载时,并不意味着里面的所有组件也都被挂载。所以我不得不添加一个超时。我不确定为什么您真的想在页面加载后立即导航,而是可以在 Frame 中嵌入登录/主页组件作为默认页面。

    【讨论】:

    • 这对我没有任何影响。文档说明它可以是 Id 或 Ref,尽管代码表明使用了 Id。都不适合我。
    • 我不是 Vue 专家,但据我所知,使用 ~ 并不等同于 id 或 ref 我猜。如果 ref 或 id 都不起作用,我建议您准备一个 Playground 示例,以便调试。
    • 谢谢。我添加了一个游乐场链接(从未想过)。我在某处读到 ~ 是 ref 的缩写,但找不到它。也许我错了。 Ref 和 Id 对我不起作用。
    • 谢谢!现在对我来说更有意义了。立即导航的想法是加载主页,但如果用户的令牌过期(或由于其他原因未登录),则导航到登录。 defaultPage 属性使应用程序崩溃。
    猜你喜欢
    • 2019-12-25
    • 2019-06-29
    • 2020-03-20
    • 2020-07-21
    • 2020-03-22
    • 2019-11-12
    • 2019-09-24
    • 2019-04-01
    • 2020-11-10
    相关资源
    最近更新 更多