1.2.1 • Published 4 years ago

vue2-localstorage v1.2.1

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

vue-storage

Describe

This plugin simplify the localStorage operation.

data type

All JS type

How to use

$ npm install vue2-localstorage
$ yarn add vue2-localstorage

Create Instance

import Vue from 'vue';
import VueStorage from 'vue2-localstorage';

Vue.use(VueStorage);

const storage = new VueStorage({
  DB_NAME : 'test-example',
  DE_KEY  : 'id', // array item's default key
  VERSION : 'v1',
  storage : [
    {
      store   : 'account-list', 
      autoKey : true, // auto provided primary key for every item
      type    : Array, // store target's type
      key     : 'id', // like every item's primary key (set as DE_KEY if not provided)
      default : [], // default value (set as [] if not provided)
    },
    {
      store   : 'remember-password',
      type    : Boolean,
      default : true,
    },
    {
      store   : 'join-info',
      type    : Object,
      default : { account: '13123371892', password: '123456' },
    },
  ],
});

if (process.env.NODE_ENV === 'development') {
  window.storage = storage;
}
export default storage;

Params

DB_NAME : database's name

DE_KAY : default key (For Array type)

VERSION : database version

storage : store items

Operation

Normal

MethodExampleDescription
getthis.$storage.get('account-list')Like localStorage.getItem
setthis.$storage.set('join-info', {"account":"admin","password":"123456"})Like localStorage.setItem
removestorage.remove('remember-password')Like localStorage.removeItem

Tip: you can operate object directly.

Advance

The plugin add some methods to handler Array

insertItem

Definition: insertItem(key, valueList)

Example:

this.$storage.insertItem('account-list', [
  {name:'userA', pass: '1234'}, 
  {name:'userB', pass: '1234'}
]);

insertOrUpdate

Definition: insertOrUpdate(key, valueList)

Example:

this.$storage.insertItem('account-list', [
  {name:'userA', pass: '1234', id: "k45olgia0.jszelqpefiq1"}, // may be updated 
  {name:'userB', pass: '1234'}
]);

if item provide the same key (such as id), item will be updated if not provide key or unique key , item will be inserted

removeItem

Definition: removeItem(key, removedKeys)

Example:

storage.removeItem('account-list', [
        'k45olgia0.jszelqpefiq1',
        'k45olgia0.412q1m7meov2'
    ])

updateItem

Definition: updateItem(key, valueList)

Example:

storage.updateItem('account-list', [
  { 
    name: "userC", 
    pass: "1234", 
    id: "k45p0gw40.a194800akpr3" 
  }
])

updateItem

Definition: getItem(key, value)

Example:

storage.getItem('account-list', 'k45p9t7r0.8n3hntpabfm5')

get value by primary key

clear

Definition: clear(key)

Example:

storage.clear('account-list')

the account-list's value will be set as []

1.2.1

4 years ago

1.2.0

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1-alpha

5 years ago

1.0.0-alpha

5 years ago