storejs an easy to use plug-local storage

store.js is a wrapper compatible LocalStorage all browsers, without the aid of Cookie or Flash. store.js will automatically choose to use localStorage, globalStorage or userData to achieve local storage depending on the browser.

This chapter describes the use store.js in vue

First, install

npm install storejs --save

Second, the introduction of

Can be globally introduced, of course, may be incorporated subassembly

Third, the use

For ease of use, we generally define global entry file

. Vue.prototype $ storeLocal = storeLocal; // assembly defined localStorage

Then call in the use of components that need:

this.$storeLocal.set('local_test',{'a':1,'b':2});

 

Can see, I will direct a json object is stored in a, storejs has helped us to deal with, but also can be used directly: console.log (. This $ storeLocal.get ( 'local_test'));

result:

 

Fourth, the common API

 

store.set('username', 'marcus')
store.get('username')
store.remove('username')
 
store.clear()
 
store.set('user', { name: 'marcus', likes: 'javascript' })
 
var user = store.get('user')
alert(user.name + ' likes ' + user.likes)
 
// Get all stored values
store.getAll().user.name == 'marcus'
 
// Loop over all stored values
store.forEach(function(key, val) {
    console.log(key, '==', val)
})

Guess you like

Origin www.cnblogs.com/linfblog/p/12150762.html