【发布时间】:2019-01-11 21:41:49
【问题描述】:
基本上我有一个带有通用登录函数和变量的 BaseAuthController,然后我有一个 SignupController 和一个从 BaseAuthController 继承的 LoginController。我已经通过断点查看了变量,并且变量都被正确设置并且它们存在。问题是更改超类中的变量而不是更新 DOM
BaseAuthController.ts
import { RouterStates } from './../../../routing/RouterStates';
import Vue from "vue";
export class BaseAuthController extends Vue
{
// Variables
// ==================================================================
protected errorMessage: string = '';
// Login handling
// ==================================================================
/**
* Handle loging in
* @param {firebase.auth.UserCredential} respone
*/
protected onLoginSuccess(respone: firebase.auth.UserCredential): void
{
if (respone.user)
{
let user: firebase.User = respone.user;
if (user.emailVerified)
{
this.$router.replace(RouterStates.APP);
}
else
{
user.sendEmailVerification()
.then(() =>
{
this.$router.replace(RouterStates.VERIFY_EMAIL);
})
.catch(err => console.log(err));
}
}
}
}
SignupController.vue
<template>
<div class="signup-controller__row">
<div class="h-group v-align-center">
<div class="signup-controller__error-image tight"></div>
<div class="signup-controller__error-message">{{ errorMessage }}</div>
</div>
</div>
</template>
<script src="./SignupController.ts"></script>
SignupController.ts
export default class SignupController extends BaseAuthController {
// Variables
// ===============================================================
private confirmPassword: string = '';
private creationDetails: AccountCreationDetails =
{
email: '',
password: ''
}
/**
* Create an account
* @returns void
*/
private onCreateAccountClick(): void
{
if (this.creationDetails && this.creationDetails.email != '')
{
if (this.creationDetails && this.creationDetails.password != '')
{
if (this.confirmPassword != '')
{
if (StringUtil.validateEmail(this.creationDetails.email))
{
if (this.creationDetails.password == this.confirmPassword)
{
firebase.auth().createUserWithEmailAndPassword(this.creationDetails.email, this.creationDetails.password)
.then((respone: firebase.auth.UserCredential) => this.onLoginSuccess(respone))
.catch(() =>
{
this.errorMessage = 'There was an issue creating your account';
});
}
else
{
this.errorMessage = 'Passwords do not match';
}
}
else
{
this.errorMessage = 'Please enter a valid email address';
}
}
else
{
this.errorMessage = 'Please confirm your password';
}
}
else
{
this.errorMessage = 'Please enter a password';
}
}
else
{
this.errorMessage = 'Please enter your email address';
console.log(this.errorMessage);
}
}
}
【问题讨论】:
标签: typescript firebase vue.js firebase-authentication