[编辑] -> 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>
我无法找出我做错了什么,也无法从源头上找出答案。任何帮助/建议将不胜感激。
最佳答案
您尚未在 RadSideDrawer
中为您的 Frame
设置 id。
为了使您的this.$navigateTo
代码工作,框架声明应该是
...
<Frame id="mainContent" ~mainContent>
...
编辑:
我已经更新了你的Playground sample .
Page
只能是Frame
的子元素。所以我必须更新你的LoginPage.vue
或HomePage.vue
来保存一个Page
。- 如果我没记错的话,RadSideDrawer 会在内部覆盖 mainContent 的引用(虽然不确定),所以 id 在这里工作得更好。
- 当组件被挂载时,并不意味着里面的所有组件也都挂载了。所以我不得不添加一个超时。我不确定为什么您真的想在页面加载后立即导航,而是可以将登录/主页组件嵌入 Frame 作为默认页面。
关于NativeScript Vue Frame navigateTo 不导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53327803/