简体   繁体   English

如何使用 typescript 使用手动路由 nativescript-vue?

[英]how to use Manual Routing nativescript-vue using typescript?

How i can use the $navigationTo using typescript in nativescript-vue?我如何使用 $navigationTo 在 nativescript-vue 中使用 typescript? i maked this work here: https://github.com/Figur8/NativescriptLoginTestVue , but when i try with typescript i get this error.我在这里完成了这项工作: https://github.com/Figur8/NativescriptLoginTestVue ,但是当我尝试使用 typescript 时,我得到了这个错误。 [Vue warn]: Unknown custom element: - did you register the component correctly? [Vue 警告]:未知的自定义元素:- 您是否正确注册了组件? For recursive components, make sure to provide the "name" option.对于递归组件,请确保提供“名称”选项。

  <template>
        <Page>
            <FlexboxLayout class="page">
                <StackLayout class="form">
                    <Image
                            src="https://www.carnegietechnologies.com/sites/ct/assets/image/logo-octopus.png"
                            loadMode="async" stretch="aspectFit"></Image>

                    <StackLayout class="input-field">
                        <TextField v-model="email" hint="email" class="input" keyboardType="email"
                                   autocorrect="false" autocapitalizationType="none" >
                        </TextField>
                        <Label class="message" :text="email"/>
                    </StackLayout>

                    <StackLayout class="input-field">
                        <TextField hint="Password" secure="true" class="input">
                        </TextField>
                    </StackLayout>
                    <Button text="Log In" class="btn btn-primary" @tap="clientLogin" ></Button>
                    <Button text="Log In" class="btn btn-primary"
                            @tap="$goTo"></Button>
                </StackLayout>
            </FlexboxLayout>
        </Page>
    </template>

    <script lang="ts">

        import Vue from 'nativescript-vue';
        import {Component} from 'vue-property-decorator';
        import Home from "./Home";

        @Component
        export default class App extends Vue {
            goTo(){
                this.$navigateTo(Home);
            }
        }
    </script>

    <style scoped>
        ActionBar {
            background-color: #53ba82;
            color: #ffffff;
        }

        .message {
            vertical-align: center;
            text-align: center;
            font-size: 20;
            color: #333333;
        }
    </style>

One thing you can do is import your routes file in your component and use the key from the routes object to redirect to.您可以做的一件事是在组件中导入路由文件,并使用路由 object 中的密钥重定向到。 For example:例如:

routes/index.js路线/index.js

import Home from './components/Home';

export default {
    home: Home,
}

In your Vue component:在您的 Vue 组件中:

import routes from '~/routes'
export default {
    methods: {
        goTo() {
            this.$navigateTo(routes.Home)
        }
    }
}

i was make this work,.我正在做这项工作,。 look my example.看我的例子。

<template for="r in result">
    <Page>
        <FlexboxLayout class="page">
            <StackLayout class="form">
                <Image
                        src="https://www.carnegietechnologies.com/sites/ct/assets/image/logo-octopus.png"
                        loadMode="async" stretch="aspectFit"></Image>
                <StackLayout class="input-field">
                    <TextField v-model="email" hint="email" class="input" keyboardType="email"
                               autocorrect="false" autocapitalizationType="none" >
                    </TextField>
                </StackLayout>

                <StackLayout class="input-field">
                    <TextField v-model="password"  hint="Password" secure="true" class="input">
                    </TextField>
                </StackLayout>
                <Button text="Log In" class="btn btn-primary" @tap="clientLogin" ></Button>
            </StackLayout>
        </FlexboxLayout>
    </Page>
</template>

<script lang="ts">
    import Vue from 'nativescript-vue';
    import {Component, Prop} from 'vue-property-decorator';
    import client from "@/lib/fusionAuthClientInstance";
    import Home from "@/components/Home.vue";

    const secure = {
        template: `
    <Page>
       <ActionBar title="Second" class="action-bar" />
        <ScrollView>
            <StackLayout class="home-panel">
                <Label>Second action action</Label>
            </StackLayout>
        </ScrollView>
    </Page>
  `
    };

    export interface result {
        statusCode: string,
        response: JSON,
        registration: Array<string>,
    }

    @Component
    export default class App extends Vue {

        private email: string ;
        private password: string;
        private request: Object;
        private roles: JSON;
        private user: any;
        public post: string;

        goTo(roleInFusionAuth){
            if(roleInFusionAuth == "view-security-message"){
                this.$navigateTo(Home);
            }else{
                alert({
                    title: "TRETA",
                    message: "Usuário ou senha incorretos",
                    okButtonText: "try Again"
                }).then(() => {
                    console.log("Alert dialog closed");
                });
            };

        };

        requestProvider(){
            this.request =  {
                "loginId": this.email,
                "password": this.password,
                "applicationId": "fca4814f-645c-4c3f-a9b0-2b2ca7a2e835"
            };
            return this.request;
        };

        testFusionAuthMethods() {
            return client.searchUsers("901904d8-5eeb-441f-a80e-8c8c595825b5")
                .then(response => {
                    console.log(response);
                });
        };

        clientLogin() {
            // this.$navigateTo(secure);
            return client.login(this.requestProvider())
                .then(this.handleResponse, this.handleErrorResponse)
                .then(response => {
                    this.result = response;
                    this.user = this.result.response;
                    this.roles = this.user.user.registrations;
                    this.post = this.roles[0].roles[0];
                })
                .then(responsibility =>{
                    console.log(this.post);
                    this.goTo(this.roles[0].roles[0]);
                });
        };



        handleResponse(clientResponse) {
            return clientResponse;
        };
        handleErrorResponse(clientResponse) {
            return clientResponse;
        };

        components: {
            Home,
        };
    }

</script>
<style scoped>
    ActionBar {
        background-color: #53ba82;
        color: #ffffff;
    }

    .message {
        vertical-align: center;
        text-align: center;
        font-size: 20;
        color: #333333;
    }
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Typescript 添加到 Nativescript-Vue 项目中? - How to add Typescript to a Nativescript-Vue project? 如何使用打字稿在 Nativescript-vue 中传递对象而不是字符串? - How to pass object instead of string in Nativescript-vue with typescript? Nativescript-vue + Typescript - HMR 不适用于 Vue Class 组件 - Nativescript-vue + Typescript - HMR not working on Vue Class Component NativeScript-Vue with Typescript in VSCode with Vetur: Alert with then giving Property 'then' does not exist on type 'void' - NativeScript-Vue with Typescript in VSCode with Vetur: Alert with then giving Property 'then' does not exist on type 'void' 使用 Typescript 支持启动新的 nativescript-vue 项目的正确方法是什么? - What is proper way of starting a new nativescript-vue project with Typescript support? 带ts-loader的NativeScript-Vue打字稿链式加载babel-loader - NativeScript-Vue typescript chainloading babel-loader with ts-loader Nativescript-vue 打字稿。 通过代码将自定义组件添加到布局容器 - Nativescript-vue Typescript. Adding custom component to a layout container through code Nativescript-Vue devtools 不更新页面 - Nativescript-Vue devtools Not updating The Page Nativescript-Vue 创建动态元素 - Nativescript-Vue creating dynamic elements 如何在nativescript中使用打字稿? - How to use typescript in nativescript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM