【问题标题】:how to use Manual Routing nativescript-vue using typescript?如何使用打字稿使用手动路由nativescript-vue?
【发布时间】:2019-10-16 18:11:29
【问题描述】:

如何在 nativescript-vue 中使用 $navigationTo 使用 typescript?我在这里完成了这项工作:https://github.com/Figur8/NativescriptLoginTestVue, 但是当我尝试使用打字稿时,我得到了这个错误。 [Vue 警告]:未知的自定义元素:- 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。

  <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>

【问题讨论】:

    标签: typescript nativescript nativescript-vue


    【解决方案1】:

    你可以做的一件事是在你的组件中导入你的路由文件,并使用路由对象中的键来重定向到。例如:

    路由/index.js

    import Home from './components/Home';
    
    export default {
        home: Home,
    }
    

    在你的 Vue 组件中:

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

    【讨论】:

    • 这对我不起作用,兄弟!谢谢你的帮助。看看我的解决方案。
    【解决方案2】:

    我是在做这个工作!看看我的例子。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-20
      • 2016-09-05
      相关资源
      最近更新 更多