Skip to content

Commit

Permalink
readme:解决 localStorage 无法及时清理的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
im0qianqian committed Apr 23, 2019
1 parent 4faf4c1 commit df2a42f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ $.pjax({
callback: function(){}
})
```
**注意:若设置 storage 为 true,为避免多次请求页面后导致本地 localStorage 容量不足而触发异常,请在页面加载完成后加载以下 JavaScript 代码清除已过期的记录。**

```javascript
if (!!window.localStorage) {
for (var key in localStorage) {
try {
if ((key.split("_") || [""])[0] === "pjax") {
var item = localStorage.getItem(key);
if (item) {
item = JSON.parse(item);
if ((parseInt(item.time) + 600 * 1000) <= new Date * 1) {
localStorage.removeItem(key)
}
}
}
} catch (e) { }
}
}
```



### qwrap版

qwrap版需要在页面引入qwrap和对应的ajax组件。
Expand Down

0 comments on commit df2a42f

Please sign in to comment.