sunnylqm / react-native-storage

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.
MIT License
3.02k stars 268 forks source link

storage.sync用require方式引入外部文件无效 #213

Closed CrisChr closed 5 years ago

CrisChr commented 5 years ago

外部fetch.js: const api = 'https://api.douban.com/v2/movie/subject' export default { async movie(params) { const { syncParams: { movieId } } = params const rawResponse = await fetch(${api}/${movieId}) const textResponse = await rawResponse.text() const jsonResponse = JSON.parse(textResponse) //console.log('json: ', jsonResponse) if (jsonResponse) { storage.save({ key: 'movie', id: movieId, data: jsonResponse }) return jsonResponse } } } storage.js: const storage = new Storage({ size: 1000, storageBackend: AsyncStorage, defaultExpires: 1000 * 60 * 2, enableCache: true, sync: require('./src/data/fetchMovieDetails') }); 将storage.sync作为一个模块导入 后台一直报Expired error,无法从服务器更新数据