简体   繁体   English

React Native AsyncStorage => TypeError:无法读取未定义的属性“登录”

[英]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.

相关问题 "React-Native AsyncStorage:TypeError:无法读取未定义的属性“setItem”" - React-Native AsyncStorage: TypeError: Cannot read property 'setItem' of undefined 反应本机“无法读取未定义的属性” AsyncStorage - React native 'Cannot read property of undefined' AsyncStorage react-native redux登录表单抛出'TypeError:无法读取未定义的属性'displayName''' - react-native redux Login Form throws an 'TypeError: Cannot read property 'displayName' of undefined'' React Native jest test:TypeError:无法读取未定义的属性'unsubscribeFromTopic' - React Native jest test: TypeError: Cannot read property 'unsubscribeFromTopic' of undefined React Native + Fetch => TypeError:无法读取未定义的属性“ then” - React Native + Fetch => TypeError: Cannot read property 'then' of undefined 反应本机TypeError:无法读取未定义的属性“导航” - react native TypeError: Cannot read property 'navigation' of undefined TypeError:无法在React Native中读取未定义的属性'receiptnumber' - TypeError: Cannot read property 'receiptnumber' of undefined in react native React Native ListView-TypeError:无法读取未定义的属性'cloneWithRows'(…) - React Native ListView - TypeError: Cannot read property 'cloneWithRows' of undefined (…) TypeError:无法读取未定义的属性“数量”。 反应原生 Redux - TypeError: Cannot read property 'qty' of undefined. React Native Redux 类型错误:无法读取未定义的 React Native 的属性“导航” - TypeError: Cannot read property 'navigate' of undefined React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM