简体   繁体   English

"React-Native AsyncStorage:TypeError:无法读取未定义的属性“setItem”"

[英]React-Native AsyncStorage: TypeError: Cannot read property 'setItem' of undefined

I'm learning react-native and trying to use AsyncStorage<\/code> .我正在学习 react-native 并尝试使用AsyncStorage<\/code> 。 I'm using this code to store the data:我正在使用此代码来存储数据:

_storeData = async (token) => {
    console.log("store token");
    console.log(token);
    try {
      await AsyncStorage.setItem('token', token);
    } catch (error) {
      // Error saving data
      console.log(error);
    }
  }

I'm learning react-native and trying to use AsyncStorage .我正在学习react-native并尝试使用AsyncStorage I'm using this code to store the data:我正在使用以下代码来存储数据:

_storeData = async (token) => {
    console.log("store token");
    console.log(token);
    try {
      await AsyncStorage.setItem('token', token);
    } catch (error) {
      // Error saving data
      console.log(error);
    }
  }

Calling it with: this._storeData(res.token);调用它: this._storeData(res.token);

But it is giving me this error:但这给了我这个错误:

> TypeError: Cannot read property 'setItem' of undefined
>     at LoginOrCreateForm._callee$ (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:138096:71)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at Generator.invoke [as _invoke] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21583:24)
>     at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21451:23)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at invoke (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21484:22)
>     at blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21514:13
>     at tryCallTwo (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22690:7)
>     at doResolve (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22854:15)
>     at new Promise (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22713:5)

Could anyone help with what I am doing wrong?有人可以帮我解决我做错的事情吗? Thanks谢谢

I'm learning react-native and trying to use AsyncStorage .我正在学习react-native并尝试使用AsyncStorage I'm using this code to store the data:我正在使用以下代码来存储数据:

_storeData = async (token) => {
    console.log("store token");
    console.log(token);
    try {
      await AsyncStorage.setItem('token', token);
    } catch (error) {
      // Error saving data
      console.log(error);
    }
  }

Calling it with: this._storeData(res.token);调用它: this._storeData(res.token);

But it is giving me this error:但这给了我这个错误:

> TypeError: Cannot read property 'setItem' of undefined
>     at LoginOrCreateForm._callee$ (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:138096:71)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at Generator.invoke [as _invoke] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21583:24)
>     at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21451:23)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at invoke (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21484:22)
>     at blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21514:13
>     at tryCallTwo (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22690:7)
>     at doResolve (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22854:15)
>     at new Promise (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22713:5)

Could anyone help with what I am doing wrong?有人可以帮我解决我做错的事情吗? Thanks谢谢

I'm learning react-native and trying to use AsyncStorage .我正在学习react-native并尝试使用AsyncStorage I'm using this code to store the data:我正在使用以下代码来存储数据:

_storeData = async (token) => {
    console.log("store token");
    console.log(token);
    try {
      await AsyncStorage.setItem('token', token);
    } catch (error) {
      // Error saving data
      console.log(error);
    }
  }

Calling it with: this._storeData(res.token);调用它: this._storeData(res.token);

But it is giving me this error:但这给了我这个错误:

> TypeError: Cannot read property 'setItem' of undefined
>     at LoginOrCreateForm._callee$ (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:138096:71)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at Generator.invoke [as _invoke] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21583:24)
>     at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21451:23)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at invoke (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21484:22)
>     at blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21514:13
>     at tryCallTwo (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22690:7)
>     at doResolve (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22854:15)
>     at new Promise (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22713:5)

Could anyone help with what I am doing wrong?有人可以帮我解决我做错的事情吗? Thanks谢谢

I'm learning react-native and trying to use AsyncStorage .我正在学习react-native并尝试使用AsyncStorage I'm using this code to store the data:我正在使用以下代码来存储数据:

_storeData = async (token) => {
    console.log("store token");
    console.log(token);
    try {
      await AsyncStorage.setItem('token', token);
    } catch (error) {
      // Error saving data
      console.log(error);
    }
  }

Calling it with: this._storeData(res.token);调用它: this._storeData(res.token);

But it is giving me this error:但这给了我这个错误:

> TypeError: Cannot read property 'setItem' of undefined
>     at LoginOrCreateForm._callee$ (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:138096:71)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at Generator.invoke [as _invoke] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21583:24)
>     at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21451:23)
>     at tryCatch (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21408:19)
>     at invoke (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21484:22)
>     at blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:21514:13
>     at tryCallTwo (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22690:7)
>     at doResolve (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22854:15)
>     at new Promise (blob:http://localhost:8081/21ec2746-a3c9-4c68-937f-ee50c63a6d58:22713:5)

Could anyone help with what I am doing wrong?有人可以帮我解决我做错的事情吗? Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native AsyncStorage =&gt; TypeError:无法读取未定义的属性“登录” - React Native AsyncStorage=> TypeError: Cannot read property 'login' of undefined 反应本机“无法读取未定义的属性” AsyncStorage - React native 'Cannot read property of undefined' AsyncStorage 'TypeError:无法读取 react-native 中未定义'的属性'getStateForAction' - 'TypeError: Cannot read property 'getStateForAction' of undefined ' in react-native react-native - 类型错误:无法读取未定义的属性“修剪” - react-native - TypeError: Cannot read property 'trim' of undefined react-native-sensitive-info 无法读取未定义的属性 setItem - react-native-sensitive-info Cannot read property setItem of undefined React-Native AsyncStorage setItem不起作用? - React-Native AsyncStorage setItem doesnt work? react-native redux登录表单抛出&#39;TypeError:无法读取未定义的属性&#39;displayName&#39;&#39;&#39; - react-native redux Login Form throws an 'TypeError: Cannot read property 'displayName' of undefined'' 无法在react-native上下文api中读取未定义的属性“状态”? - Cannot read property 'state' of undefined in react-native context api? 如何解决无法读取react-native上未定义的属性“ push”? - how to solve Cannot read property 'push' of undefined on react-native? React-native:无法读取未定义的属性“ navigate” - React-native:cannot read property 'navigate' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM