适用于Ionic 3的本地存储 [英] Appropriate Local Storage for Ionic 3

查看:89
本文介绍了适用于Ionic 3的本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读本地存储,我很困惑。我看到有两种选择:

I am reading about Local Storage and I am quite confused. As I see there are two options:

原生存储,导入{NativeStorage}
离子存储,导入{IonicStorageModule}
我的应用程序是用Ionic 3和我试图在从Parse Server检索它之后保存一个对象localy数组。

Native Storage , import { NativeStorage } Ionic Storage, import { IonicStorageModule } My app is developed with Ionic 3 and I am trying to save an array of object localy after retrieve it from Parse Server.

使用Ionic 1我存储了像这样的对象数组:

With Ionic 1 I stored the objects array like this:

setUsers (users){
    window.localStorage.users_data = JSON.stringify(users);
}
getUsers(){
   return JSON.parse(window.localStorage.users_data || '[]');
}

现在,保存我的数据并将它们串起来的最佳选择是什么?解析它们?

So now, what is the best option to save my data and stringfy them and parse them?

原生存储或离子存储?

非常感谢

推荐答案

您可以轻松使用 Ionic 存储 模块。您只需要安装 SQLite 插件。详情见上述文档。然后你可以在 iOS Android 上原生使用它而不会出现任何问题。

You can easily use Ionic storage module here. You just need to install SQLite plugin. Details are in the above doc. Then you can use it natively on iOS and Android too without any issue.

用法:

 // set a key/value
  storage.set('name', 'Max');

  // Or to get a key/value pair
  storage.get('age').then((val) => {
    console.log('Your age is', val);
  });

这篇关于适用于Ionic 3的本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆