首页 > 其他分享> > 2022-08-05 [TypeError: undefined is not an object (evaluating '_asyncStorage.AsyncStorage.setIt
2022-08-05 [TypeError: undefined is not an object (evaluating '_asyncStorage.AsyncStorage.setIt
作者:互联网
前言:使用AsyncStorage来设置本地缓存
引入:
import { AsyncStorage } from "@react-native-community/async-storage";
使用:
await AsyncStorage.setItem('user_img', image.path);
报错:
[TypeError: undefined is not an object (evaluating '_asyncStorage.AsyncStorage.setItem')]
原因:引入方式错误。
解决方案:去掉花括号,即:
import AsyncStorage from "@react-native-community/async-storage";
注:如果你引入的是react-native而不是@react-native-community/async-storage这个包,那么你可以使用花括号。
标签:AsyncStorage,undefined,05,storage,community,react,setItem,TypeError,native 来源: https://www.cnblogs.com/iuniko/p/16554984.html