Appropriate Local Storage for Ionic 3

风格不统一 提交于 2019-12-10 03:46:59

问题


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

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.

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?

Native storage or Ionic Storage?

Thank you a lot


回答1:


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.

Usage:

 // 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);
  });



回答2:


Nowadays I work with ionic 4 and I have experienced unpleasant latency of the @ionic/storage module, but after I switched to the @ionic-native/native-storage I got a better performance. And by the way you still can use it while testing with the browser using the ionic cordova run browser command not the ionic serve command.

So what I am trying to say that native plugins always win in the matter of performance.

Best Wishes



来源:https://stackoverflow.com/questions/46629594/appropriate-local-storage-for-ionic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!