1:单纯的存储和读取: 存储方法:_saveData=()=>{storage.save({key:'loginState',data:{userid:'111 userid',},//expires为有效时间expires:1000*3600})}; //读取方法_readData=()=>{storage.load({key:'loginState',// autoSync(默认为true)意味着在没有找到数据或数据过期时自动调用相应的sync方法au...
对于web使用window.localStorage//如果不指定则数据只会保存在内存中,重启后即丢失storageBackend: AsyncStorage,//数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期defaultExpires: 1000 * 3600 * 1,//一个小时//读写时在内存中缓存数据。
默认值1000条数据循环存储size:1000,// 存储引擎:对于RN使用AsyncStorage,对于web使用window.localStorage// 如果不指定则数据只会保存在内存中,重启后即丢失storageBackend:AsyncStorage,// 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期defaultExpires:1000*3600...
data: userA, expires: 1000 * 60 }); //load 读取 storage.load({ key: 'user', id: '1001' }).then(ret => { // 如果找到数据,则在then方法中返回 console.log(ret.userid); }).catch(err => { // 如果没有找到数据且没有sync方法, // 或者有其他异常,则在catch中返回 console.warn(er...
{// 最大容量,默认值1000条数据循环存储size:1000,// 存储引擎:RN使用AsyncStorage// 如果不指定则数据只会保存在内存中,重启后即丢失storageBackend:AsyncStorage,// 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期defaultExpires:null,// 读写时在内存中缓存数据,默认开启enableCache:...
{// 最大容量,默认值1000条数据循环存储size:size,// 存储引擎:对于RN使用AsyncStorage,对于web使用window.localStorage// 如果不指定则数据只会保存在内存中,重启后即丢失storageBackend:AsyncStorage,// 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期defaultExpires:defaultExpires,// 读写...
import Storage from 'react-native-storage'; var storage = new Storage({ size: 1000, defaultExpires: null, enableCache: true, }) global.storage = storage; Owner sunnylqm commented Aug 3, 2016 • edited 你创建一个js文件,可以,没问题,——然而它什么时候执行呢,以及甚至它到底执行过没??
expires: 1000 * 60 }); // load storage .load({ key: 'user', id: '1001' }) .then(ret => { // found data goes to then() console.log(ret.userid); }) .catch(err => { // any exception including data not found // goes to catch() console.warn(err.message); switch (err....
defaultExpires: null, // 读写时在内存中缓存数据。默认启用。 enableCache: true, // 你可以在构造函数这里就写好sync的方法 // 或是在任何时候,直接对storage.sync进行赋值修改 // 或是写到另一个文件里,这里require引入 // 如果storage中没有相应数据,或数据已过期, // 则会调用相应的sync方法,无缝返回...
defaultExpires:null, // 读写时在内存中缓存数据,默认开启 enableCache:true, // 如果storage中没有相应数据,或数据已过期, // 则会调用相应的sync方法,无缝返回最新数据。 // sync方法的具体说明会在后文提到 // 你可以在构造函数这里就写好sync的方法 ...