如何在本机脚本中导航另一个页面?

How to navigate another page in native-script?

我正在尝试在名为 'login' 的本机脚本上创建一个简单的按钮。我已经创建了一个登录组件,但是当我测试代码时,它说元素登录没有已知组件。

<template>
<Page>
    <TabView height="100%" />
    <ActionBar title="Home" />
    <ScrollView>
        <StackLayout class="home-panel">
            <!--Add your page content here-->
            <Label textWrap="true" text="Play with NativeScript!"
                class="h2 description-label" />
            <Button text="Login" @tap="onLoginTap" />
            <Login>
        </StackLayout>
    </ScrollView>
    </TabView>
</Page>
</template>

<script>
import Login from "./login";
export default {
    data() {
        return {};
    };
},
methods: {
    onLoginTap: function() {
        this.$navigateTo(Login);
    });
</script>

您的代码中存在各种问题

  • 您只能在页面之间导航,您的登录组件未被页面元素包裹
  • 我不确定您为什么要使用 TabView,它仅在您具有选项卡式应用程序并且存在特定组件层次结构时使用。有关详细信息,请参阅文档。我已将其删除,因为您的主页似乎不需要它
  • 您不应该在同一页面中将登录作为标签嵌入

总的来说,我建议您阅读文档的基础知识以避免此类问题。

Updated Playground