Closed 1111mp closed 6 years ago
我现在需要在用户第一次打开app的时候,首页的数据是需要通过接口请求获取然后缓存起来 之后再打开app首页数据就直接读取缓存 然后现在就是我不能判断是否是第一次打开app 因为我在首页的componentWillMount中读取storage的时候无论是成功还是失败的回调都没有执行 storage.load({ key: 'newsData', id: 'newsData', autoSync: false, syncInBackground: false, syncParams: params }).then(res=>{ console.warn('11111') console.warn('res') console.warn(res) // homeStore.newsData = res }).catch(err=>{ console.warn('222222') console.warn(err) }) 成功和失败的回调都没有执行,这时候我还没有存过newsData的缓存 export default { //个人信息 userInfo(params){ let { syncParams } = params; USERINFO(syncParams).then(res=>{ storage.save({ key: 'userInfo', id: 'userInfo', data: res.data, expires: 1000*86400 //缓存时间24小时 }) },err=>{
}) }, //新闻通知 newsData(params){ let { syncParams } = params; GETNEWSANDRULES(syncParams).then(res=>{ storage.save({ key: 'newsData', id: 'newsData', data: res.data.list, expires: 1000*86400 //缓存时间24小时 }) },err=>{ }) }
} 这个是我的async方法 这个问题导致我无法判断缓存是否存在,之后的逻辑就无法实现 麻烦解答一下 谢谢啊
https://github.com/sunnylqm/react-native-storage/issues/147
我现在需要在用户第一次打开app的时候,首页的数据是需要通过接口请求获取然后缓存起来 之后再打开app首页数据就直接读取缓存 然后现在就是我不能判断是否是第一次打开app 因为我在首页的componentWillMount中读取storage的时候无论是成功还是失败的回调都没有执行 storage.load({ key: 'newsData', id: 'newsData', autoSync: false, syncInBackground: false, syncParams: params }).then(res=>{ console.warn('11111') console.warn('res') console.warn(res) // homeStore.newsData = res }).catch(err=>{ console.warn('222222') console.warn(err) }) 成功和失败的回调都没有执行,这时候我还没有存过newsData的缓存 export default { //个人信息 userInfo(params){ let { syncParams } = params; USERINFO(syncParams).then(res=>{ storage.save({ key: 'userInfo', id: 'userInfo', data: res.data, expires: 1000*86400 //缓存时间24小时 }) },err=>{
} 这个是我的async方法 这个问题导致我无法判断缓存是否存在,之后的逻辑就无法实现 麻烦解答一下 谢谢啊