爲localStorage增長過時時間和類型支持

Easy Storage

爲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

安裝

CDN

<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

npm install syt-easy-storage --save
// ES
import EasyStorage 'syt-easy-storage'
// commonjs
const EasyStorage = require('syt-easy-storage')

const es = new EasyStorage()

VueJS

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')
相關文章
相關標籤/搜索