当前位置: 首页 > 工具软件 > store.js > 使用案例 >

store.js过期时间设置

齐献
2023-12-01


前言

``

比较好用的一个本地存储插件,如何使用store.js设置一个过期时间。


``

一、store.js是什么?

本地存储localstorage的封装,提供简单的API。

二、使用步骤

1.安装

代码如下(示例):

# bower 安装 
bower install storejs
# npm 安装 
npm install storejs

2.使用事例

代码如下(示例):

// 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地址

 类似资料: