1.0.1 • Published 8 years ago
vuesession v1.0.1
vuesession
A simple session plugin for Vue.js.
v1.0.1 Highlights
- Fix
delete. - Fix
timeout.
Introduction
This project is my own implementation and is based on vue-session. Go check it out, too!
Installation
- Install with npm:
npm install vuesession
Include
Include vuesession in your project.
import Vue from 'vue'
import VueSession from 'vuesession'
Vue.use(VueSession)Configuration
vuesession offers tiny configuration.
// by default from src/
config: {
/**
* The key for the session.
*
* Default is 'vue-sess-key'
*/
key: 'vue-sess-key',
/**
* Set to 'local' for LocalStorage or
* set to 'session' for SessionStorage
*/
saveTo: 'local'
}To override default configuration, add options:
// override config
Vue.use(VueSession, {
saveTo: 'session'
// , ...
})You can now access the $sess property through your components.
Usage
this.$sess.get([key])- returns all ifkeyis not setthis.$sess.set(obj [, callback(obj, set)])- add an object, callcallbackfunction after set, returnstrueif successfulthis.$sess.exists([key])- returnstrueif session or akeyvalue existsthis.$sess.delete(key)- returnstrueif successful delete ofkeythis.$sess.destroy()- returnstrueif successfully removedvuesessionkeythis.$sess.timer(key, callback(get), timeout(get))- ifkeyexists, docallback;timeoutreturns msecthis.$sess.timeout(key, logged, until [, callback(get, res)])-loggedtime,untilwhat timekeyexpires, and callcallbackafter expiration
Example
For the detailed example, go here.
Copyright and License
vuesession is licensed under the MIT License.
Note
Have fun and happy coding!