[英]React Native AsyncStorage=> TypeError: Cannot read property 'login' of undefined
This error occur while calling login function:调用登录function时出现此错误:
TypeError: Cannot read property 'login' of undefined
TypeError:无法读取未定义的属性“登录”
How to solve that problem error calling login() function.如何解决调用 login() function 时出错的问题。 I called login() in AsyncStorage multiSet callback function.
我在 AsyncStorage multiSet 回调 function 中调用了 login()。 when I try to access the other property by using this keyword or without any keywords it occurs property not found.
当我尝试使用此关键字或不使用任何关键字来访问其他属性时,会出现找不到属性。
facebookLogin() {
LoginManager.logInWithPermissions(["public_profile","email","user_birthday","user_friends"]).then(
function(result) {
if (result.isCancelled) {
console.log("Login cancelled");
} else {
console.log(
"Login success with permissions: " +
result.grantedPermissions.toString()
);
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString());
fetch('https://graph.facebook.com/v2.5/me?fields=email,name,friends,birthday&access_token=' + data.accessToken)
.then((response) => response.json())
.then((json) => {
AsyncStorage.multiSet([
['name', json.name.toString()],
['email', json.email.toString()],
['photo', 'http://graph.facebook.com/'+json.id+'/picture?type=square']],
() => {
console.log("FACEBOOK Login Successeded..");
this.login();
});
})
.catch(() => {
console.log('ERROR GETTING DATA FROM FACEBOOK')
});
}
);
}
},
function(error) {
console.log("Login fail with error: " + error);
}
);
}
login = () => {
this.props.navigation.replace("Dashboard");
}
Just replace your facebookLogin() {... }.只需替换您的 facebookLogin() {... }。 with facebookLogin = () => {... }
用 facebookLogin = () => {... }
With this fat arrow function.用这个胖箭头 function。 Hope this helps.
希望这可以帮助。 feel free for doubts
随时怀疑
Replace this code "this.login()" with "this.login"将此代码“this.login()”替换为“this.login”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.