如何解决TypeError:尽管函数返回promise,但无法读取未定义的属性“ then”
class Firebase {
constructor() {
app.initializeApp(firebaseConfig);
this.auth = app.auth();
}
doCreateUserWithEmailAndPassword = (email,password) => {
this.auth.createUserWithEmailAndPassword(email,password);
};
}
用Firebase.doCreateUserWithEmailAndPassword()
调用.then()
方法时,我得到以下错误方法:
TypeError:无法读取未定义的属性“ then”
解决方法
我认为许多初学者都面临这个问题,所以我想分享我的解决方案。
由于箭头函数的语法,应该删除doCreateUserWithEmailAndPassword方法周围的{},以便返回this.auth.createUserWithEmailAndPassword()的结果
或
我本可以保留{}并添加一个return语句。
所以正确的方法应该是:
doCreateUserWithEmailAndPassword = (email,password) =>
this.auth.createUserWithEmailAndPassword(email,password);
或
doCreateUserWithEmailAndPassword = (email,password) => {
return this.auth.createUserWithEmailAndPassword(email,password);
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。