反应本机加载图像并存储在设备中?
React native Loading image and store in Device?
我正在为 ios 和 android 创建 React Native 应用程序
在应用程序中,有很多图像和 gif 会增加应用程序的大小
解决问题我将图片上传到服务器并从服务器加载
**但问题是我不希望每次用户打开应用程序加载图像,而是我需要将它们存储在本地存储中并从那里读取,如果图像在本地存储上不可用,那么它将下载并存储在那里.需要在原生反应中做到这一点的最佳方式**
React 本机版本 0.64
在调用 api 从服务器获取图像之前,如果您使用的是 AsyncStorage,请检查图像是否存储在 AsyncStorage
中
const loadLocalImages = async() => {
try {
const images = await AsyncStorage.getItem('@images_Key');
if(images !== null) {
//set your variables
}else {
//fetch images from api
}
}cache(e){
//log error if any
}
}
我正在为 ios 和 android 创建 React Native 应用程序 在应用程序中,有很多图像和 gif 会增加应用程序的大小 解决问题我将图片上传到服务器并从服务器加载 **但问题是我不希望每次用户打开应用程序加载图像,而是我需要将它们存储在本地存储中并从那里读取,如果图像在本地存储上不可用,那么它将下载并存储在那里.需要在原生反应中做到这一点的最佳方式** React 本机版本 0.64
在调用 api 从服务器获取图像之前,如果您使用的是 AsyncStorage,请检查图像是否存储在 AsyncStorage
中const loadLocalImages = async() => {
try {
const images = await AsyncStorage.getItem('@images_Key');
if(images !== null) {
//set your variables
}else {
//fetch images from api
}
}cache(e){
//log error if any
}
}