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

写了一个Storage.JS #85

Closed
Rcrosp opened this issue Apr 20, 2017 · 13 comments
Closed

写了一个Storage.JS #85

Rcrosp opened this issue Apr 20, 2017 · 13 comments

Comments

@Rcrosp
Copy link

Rcrosp commented Apr 20, 2017

import { AsyncStorage } from 'react-native';
import Storage from 'react-native-storage';

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

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

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

    // 读写时在内存中缓存数据。默认启用。
    enableCache: true,

    // 如果storage中没有相应数据,或数据已过期,
    // 则会调用相应的sync方法,无缝返回最新数据。
    // sync方法的具体说明会在后文提到
    // 你可以在构造函数这里就写好sync的方法
    // 或是写到另一个文件里,这里require引入
    // 或是在任何时候,直接对storage.sync进行赋值修改
    sync: require('./sync')
})

global.storage = storage;

在别的地方引用,出现ReferenceError: storage is not defined,在入口引用该JS直接报错,请问是什么原因

@sunnylqm
Copy link
Owner

引用报什么错

@Rcrosp
Copy link
Author

Rcrosp commented Apr 20, 2017

@Rcrosp
Copy link
Author

Rcrosp commented Apr 20, 2017

import storage from './app/utils/RTStorage';

@sunnylqm
Copy link
Owner

截图贴出来

@sunnylqm
Copy link
Owner

import报错 99%的可能就是路径错了
另外你这里只需要import 不需要from 因为并没有export

@Rcrosp
Copy link
Author

Rcrosp commented Apr 20, 2017

import 路径?

@sunnylqm
Copy link
Owner

import '路径'

@Rcrosp
Copy link
Author

Rcrosp commented Apr 20, 2017

还是出错
wechatimg1

@sunnylqm
Copy link
Owner

删掉node_modules重新npm install

@Rcrosp
Copy link
Author

Rcrosp commented Apr 20, 2017

还是一样

@sunnylqm
Copy link
Owner

关闭debug再看

@sunnylqm
Copy link
Owner

请仔细先看看文档吧

@Rcrosp
Copy link
Author

Rcrosp commented Apr 20, 2017

解决了,thx

@Rcrosp Rcrosp closed this as completed Apr 20, 2017
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

2 participants