![](/img/trans.png)
[英]React Native AsyncStorage=> TypeError: Cannot read property 'login' of undefined
[英]React-Native AsyncStorage: TypeError: Cannot read property 'setItem' of undefined
我正在學習 react-native 並嘗試使用
AsyncStorage<\/code> 。
我正在使用此代碼來存儲數據:
_storeData = async (token) => {
console.log("store token");
console.log(token);
try {
await AsyncStorage.setItem('token', token);
} catch (error) {
// Error saving data
console.log(error);
}
}
我正在學習react-native並嘗試使用AsyncStorage
。 我正在使用以下代碼來存儲數據:
_storeData = async (token) => {
console.log("store token");
console.log(token);
try {
await AsyncStorage.setItem('token', token);
} catch (error) {
// Error saving data
console.log(error);
}
}
調用它: this._storeData(res.token);
但這給了我這個錯誤:
> 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)
有人可以幫我解決我做錯的事情嗎? 謝謝
我正在學習react-native並嘗試使用AsyncStorage
。 我正在使用以下代碼來存儲數據:
_storeData = async (token) => {
console.log("store token");
console.log(token);
try {
await AsyncStorage.setItem('token', token);
} catch (error) {
// Error saving data
console.log(error);
}
}
調用它: this._storeData(res.token);
但這給了我這個錯誤:
> 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)
有人可以幫我解決我做錯的事情嗎? 謝謝
我面臨着同樣的問題。
如果你正在使用
然后按照https:\/\/react-native-async-storage.github.io\/async-storage\/docs\/install\/<\/a>在您的項目中安裝 AsyncStorage。
安裝和鏈接完成后,將其導入您的項目:
import AsyncStorage from '@react-native-async-storage/async-storage';
我正在學習react-native並嘗試使用AsyncStorage
。 我正在使用以下代碼來存儲數據:
_storeData = async (token) => {
console.log("store token");
console.log(token);
try {
await AsyncStorage.setItem('token', token);
} catch (error) {
// Error saving data
console.log(error);
}
}
調用它: this._storeData(res.token);
但這給了我這個錯誤:
> 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)
有人可以幫我解決我做錯的事情嗎? 謝謝
我正在學習react-native並嘗試使用AsyncStorage
。 我正在使用以下代碼來存儲數據:
_storeData = async (token) => {
console.log("store token");
console.log(token);
try {
await AsyncStorage.setItem('token', token);
} catch (error) {
// Error saving data
console.log(error);
}
}
調用它: this._storeData(res.token);
但這給了我這個錯誤:
> 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)
有人可以幫我解決我做錯的事情嗎? 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.