RN 持久化数据存储

2019-06-11  本文已影响0人  ios_wong

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
    }
  }
上一篇下一篇

猜你喜欢

热点阅读