Javascript TypeError:无法读取属性';设置';在React native中未定义的
我正在使用KeyValueStorage调用异步方法,我从“react native key-value-storage”导入了KeyValueStorage,但不知道出了什么问题Javascript TypeError:无法读取属性';设置';在React native中未定义的,javascript,react-native,react-native-android,Javascript,React Native,React Native Android,我正在使用KeyValueStorage调用异步方法,我从“react native key-value-storage”导入了KeyValueStorage,但不知道出了什么问题 import KeyValueStorage from "react-native-key-value-storage" onsuccessLogin =async () => { try { await KeyValueStorage.set("userI
import KeyValueStorage from "react-native-key-value-storage"
onsuccessLogin =async () => {
try {
await KeyValueStorage.set("userId", data.userId);
await KeyValueStorage.set("token", data.token);
Actions.drawerMenu();
} catch(error) {
// Handle error
console.log("Login-Error",error);
}
};
使用而不是KeyValueStorage它与您正在使用的相同
但不能在这种情况下传递整型值,必须将它们转换为字符串
这很简单
等待AsyncStorage.setItem('userId',''+userId+'')强>
其中,userId是键,userId是整型值,我们使用“”将内部值转换为字符串
希望它能帮助您并节省您的时间,因为我浪费了两天时间在AsyncStorage中传递整型值。尝试
setItem
而不是set
。当您在react native中有异步存储可用时,为什么要使用keyvalue storage!!!!setItem可用于AsyncStorage@DavidGildour!请使用由react本地社区自己开发的AsyncStorage。它的语法要简单得多。实际上,我刚刚在react native中导入了项目和新手。让我试试AsyncStorage谢谢大家@GauravRoy,abhikumar22