爲localStorage和session增長類型支持和過時時間。javascript
支持 String, Number, Array, Object.html
Function | Example |
---|---|
set | es.set('key', value, timeStamp ) |
get | es.get('key') |
remove | es.remove('key') |
clear | es.clear() |
set方法的第三個參數是一個以毫秒爲單位的時間,表示過多久過時。vue
<script type="text/javascript" src="//unpkg.com/syt-easy-storage@0.0.3/index.js"></script> <script type="text/javascript"> const es = new EasyStorage() // Default use localStorage, `new EasyStorage({type: 'session'})` for use sessionStorage </script>
npm install syt-easy-storage --save
// ES import EasyStorage 'syt-easy-storage' // commonjs const EasyStorage = require('syt-easy-storage') const es = new EasyStorage()
npm install syt-easy-storage --save
// plugin.js import VueEasyStorage 'syt-easy-storage/vue' const easyStorage = new VueEasyStorage() export default easyStorage // entry.js import Vue from 'vue' import easyStorage 'path/of/plugin.js' Vue.use(easyStorage) // components file this.$es.set('key', value) this.$es.set('key', value, 24*60*60*1000) this.$es.get('key')