我正在尝试制作,以便用户可以登录页面,但是向我展示了这种按摩"无法读取属性'$ router'undefined'
我的VUE登录代码,它在导出默认值
内import {fb} from "../firebase";
import router from '../router';
export default {
name: "NavBar",
components: {...},
data() {
return {
login: false,
register: false,
name: null,
email: null,
pwd: null,
};
},
methods: {
logInner(){
fb.auth().signInWithEmailAndPassword(this.email, this.pwd)
.then(function(){
this.$router.replace('users');
})
.catch(function(error) {`enter code here`
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
});
},
registering() {
fb.auth().createUserWithEmailAndPassword(this.email, this.pwd)
.then((user) =>{
this.$router.replace('users');
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode == "auth/weak-password") {
alert("The password is too weak.");
} else {
alert(errorMessage);
}
console.log(error);
});
}
}
};
我尝试了路由器。有人可以帮助吗?
this
在fb.auth()函数中不可用,因此请在下面尝试。有关详细说明,请检查此答案:https://stackoverflow.com/a/47148828/9489397
logInner(){
let self = this
fb.auth().signInWithEmailAndPassword(this.email, this.pwd)
.then(function(){
self.$router.replace('users');
})
和
registering() {
let self = this
fb.auth().createUserWithEmailAndPassword(this.email, this.pwd)
.then((user) =>{
self.$router.replace('users');
})