``
比较好用的一个本地存储插件,如何使用store.js设置一个过期时间。
``
本地存储localstorage的封装,提供简单的API。
代码如下(示例):
# bower 安装
bower install storejs
# npm 安装
npm install storejs
代码如下(示例):
// Example plugin usage:
import storage from 'store'
var expirePlugin = require('store/plugins/expire')
storage.addPlugin(expirePlugin)
storage.set('foo', 'bar', new Date().getTime() + 3000) // Using expire plugin to expire in 3 seconds
因为使用sessionStorage关闭浏览器之后,用户的凭证就会失效从而需要重新登录。在登录之后使用store.js设置凭证,关闭浏览器之后也能有一定的时效性,过期时间可以自行定制也可以使用后端返回的时间。
store.js的github地址