Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please do not use "_" in key!"data" is required in save()! #251

Open
GlimmerExands opened this issue Jul 24, 2020 · 0 comments
Open

Please do not use "_" in key!"data" is required in save()! #251

GlimmerExands opened this issue Jul 24, 2020 · 0 comments

Comments

@GlimmerExands
Copy link

-----storage.js-----
import Storage from 'react-native-storage';
import AsyncStorage from '@react-native-community/async-storage';

const storage = new Storage({
// 最大容量,默认值1000条数据循环存储
size: 1000,

// 存储引擎:对于RN使用AsyncStorage,对于web使用window.localStorage
// 如果不指定则数据只会保存在内存中,重启后即丢失
storageBackend: AsyncStorage,

// 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期
defaultExpires: null,

// 读写时在内存中缓存数据。默认启用。
enableCache: true, // 你可以在构造函数这里就写好sync的方法 // 或是在任何时候,直接对storage.sync进行赋值修改 // 或是写到另一个文件里,这里require引入

// 如果storage中没有相应数据,或数据已过期,
// 则会调用相应的sync方法,无缝返回最新数据。
// sync方法的具体说明会在后文提到
// sync: require('你可以另外写一个文件专门处理sync'),
});
global.storage = storage;

--------App.js--------------
import storage from './src/util/storage';

--------***.js-------------
storage.save({
key: 'user', // 注意:请不要在key中使用_下划线符号!
id: '1001', // 注意:请不要在id中使用_下划线符号!
data: '111111',
expires: 1000 * 60,
});
调用key-id保存方法时保存,报错信息:
[Fri Jul 24 2020 15:14:28.988] ERROR Please do not use "_" in key!
[Fri Jul 24 2020 15:14:29.800] ERROR "data" is required in save()!
[Fri Jul 24 2020 15:14:29.200] ERROR "data" is required in save()!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant