iOS 提供的AsyncStorage 键值对存储API已弃用.已更新为react-native-community/react-native-async-storage
使用步骤:
1、install
npm install @react-native-community/async-storage --save
2、link
react-native link @react-native-community/async-storage
3、store data
_storeData = async () => {
try {
await AsyncStorage.setItem('@storage_Key', this.state.storeItem)
} catch (e) {
}
}
4、get data
_getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
this.setState({storedData : value})
}
} catch(e) {
// error reading value
}
}
网友评论