react native 本地存储 AsyncStorage

An asynchronous, unencrypted, persistent, key-value storage system for React Native.

Async Storage 只能用来储存字符串数据,所以为了去储存object类型的数据,得先进行序列化(JSON.stringify())当你想要使用数据的时候,就可以使用JSON.parse()

An asynchronous, unencrypted, persistent, key-value storage system for React Native.

Async Storage 只能用来储存字符串数据,所以为了去储存object类型的数据,得先进行序列化(JSON.stringify())当你想要使用数据的时候,就可以使用JSON.parse()

 

import AsyncStorage from '@react-native-async-storage/async-storage'

  useEffect(() => {
    Api.h5.uploadGetTokenForH5().then(async (res) => {
      if (res.code === 200) {
        await AsyncStorage.setItem('qiniuUploadTokenForH5', res.data.token)
        const qiniuUploadTokenForH5 = await AsyncStorage.getItem('qiniuUploadTokenForH5')
        console.log('qiniuUploadTokenForH5', qiniuUploadTokenForH5)
      }
    })
  }, [])

react native 本地存储 AsyncStorage_第1张图片

react native 本地存储 AsyncStorage_第2张图片 

 

参考链接:

https://chat.xutongbao.top/

https://github.com/react-native-async-storage/async-storage#readme

你可能感兴趣的:(react,native,react.js,javascript)