# sessionStorage
# 快速导航
# 设置seesionStorage
setStorageData(key, value) {
sessionStorage.setItem(key, value);
},
1
2
3
2
3
# 获取sessionStorage
getStorageData(key) {
const str = sessionStorage.getItem(key);
if (typeof str == "string") {
try {
return JSON.parse(str);
} catch (e) {
return str;
}
}
return str;
},
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
例如:在做分页时,点击页码,刷新页面时,仍停留在当前页,而不回到第一页
created() {
this.pageNo = this.getStorageData("currentPage") || 1;
console.log("当前页", this.pageNo);
},
// 跳转页,currentPage 当前页改变时会触发
pageCurrentChange(pageNo) {
this.pageNo = pageNo;
this.setStorageData("currentPage", this.pageNo);
// this.getProjectList();
console.log("跳转页,currentPage 当前页改变时会触发");
},
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
← localStorage存储 复制文本 →