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.
Vue
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 configVue
You can now access the $sess
property through your components.
Usage
this.$sess.get([key])
- returns all ifkey
is not setthis.$sess.set(obj [, callback(obj, set)])
- add an object, callcallback
function after set, returnstrue
if successfulthis.$sess.exists([key])
- returnstrue
if session or akey
value existsthis.$sess.delete(key)
- returnstrue
if successful delete ofkey
this.$sess.destroy()
- returnstrue
if successfully removedvuesession
keythis.$sess.timer(key, callback(get), timeout(get))
- ifkey
exists, docallback
;timeout
returns msecthis.$sess.timeout(key, logged, until [, callback(get, res)])
-logged
time,until
what timekey
expires, and callcallback
after expiration
Example
For the detailed example, go here.
Copyright and License
vuesession is licensed under the MIT License.
Note
Have fun and happy coding!