我如何使用$ navigationTo在nativescript-vue中使用打字稿?我在这里做了这项工作: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>
答案 0 :(得分:0)
您可以做的一件事是在您的组件中导入路由文件,并使用来自路由对象的密钥重定向到。例如:
routes / index.js
import Home from './components/Home';
export default {
home: Home,
}
在您的Vue组件中:
import routes from '~/routes'
export default {
methods: {
goTo() {
this.$navigateTo(routes.Home)
}
}
}
答案 1 :(得分:0)
我正在做这个!!看我的例子。
<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>