【原】灵活运用sessionStorage或者localStorage
有时,一个app
中,后台并没有提供页面中对应的信息接口,需要前端在页面跳转时把某些信息带入下一个页面,一般想到用url
后带参数的方法,但是有时需要带的参数过长,就不适合用这个方法了,所以用sessionStorage
或者localStorage
可以解决这个问题。
自己写的一个简单的函数
function setSession(item, jsonData){
window.sessionStorage.setItem(item, JSON.stringify(jsonData));
};
function getSession(item){
return JSON.parse(window.sessionStorage.getItem(item));
}
function removeSession(item){
window.sessionStorage.removeItem(item);
}
另外,有时不要把sessionStorage
中的数据弄得太复杂,一个json
就可以了,最好不要json
再套json
,这样调用起来会非常繁琐,而且判断和管理控制起来也不方便。
还有,如果在sessionStorage
中没有找到对应的字段,返回的是null
。
【原】灵活运用sessionStorage或者localStorage的更多相关文章
- sessionStorage、localStorage简介
简介 技术一般水平有限,有什么错的地方,望大家指正. sessionStorage.localStorage.cookie这三个是我们在浏览器端用来存储数据的,cookie使用起来较为繁琐以后进行总结 ...
- sessionStorage 和 localStorage 、cookie
sessionStorage 和 localStorage html5中web storage包括两种储存方式:sessionStorage 和 localStorage sessionStorage ...
- HTMl5的存储方式sessionStorage和localStorage详解
html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage.sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有 ...
- html5 sessionStorage 与 localStorage存储
sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有在同一个会话中的页面才能访问并且当会话结束后数据也随之销毁.因此sessionStorage不是一种持久化的本地 ...
- cookies,sessionStorage 和 localStorage区别
cookies,sessionStorage 和 localStorage 的区别 cookie是网站为了标示用户身份而储存在用户本地终端(Client Side)上的数据(通常经过加密). cook ...
- HTMl5的sessionStorage和localStorage
HTMl5的sessionStorage和localStorage html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessionSt ...
- sessionStorage 、localStorage 与cookie 的异同点
cookie 容量4kb,默认各种浏览器都支持,缺陷就是每次请求,浏览器都会把本机存的cookies发送到服务器,无形中浪费带宽.userdata,只有ie支持,单个容量64kb,每个域名最多可存10 ...
- HTML5中的sessionStorage和localStorage
html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessionStorage用于本地存储一个会话(session)中的数据,这些数据只 ...
- [Html5]sessionStorage和localStorage常见操作
摘要 [Html5]sessionStorage和localStorage的区别 索引 上篇文章简单介绍了它们的区别,已经常见的用法.那我们能通过. 或者类似dic[key]的方式访问吗?答案是当然可 ...
随机推荐
- 微信小程序开发技巧及填坑记录
以下是自己在开发过程中遇到的坑和小技巧,记录以下: 1.出现了 page[pages/XXX/XXX] not found.May be caused by :1. Forgot to add pag ...
- "****" is not translated in zh, zh_CN.的解决方法
最近在开发一个app,要用到静默安装等一些小技术,但是引发了问题如下: 在Android SDK Tool r19之后, Export的时候遇到xxx is not translated in yyy ...
- c# 强制转换, 隐式转换, 显式转换
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- iOS各版本图标尺寸汇总
About Information Property List Files UILaunchImageFile UILaunchImageFile (String - iOS) specifies t ...
- dyld: Library not loaded...
Libraries and frameworks are designated as Required by default, but you can change this designation ...
- Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- Hadoop集群搭建安装过程(一)(图文详解---尽情点击!!!)
Hadoop集群搭建(一)(上篇中讲到了Linux虚拟机的安装) 一.安装所需插件(以hadoop2.6.4为例,如果需要可以到官方网站进行下载:http://hadoop.apache.org) h ...
- 如何通过IP地址添加网络打印机
以惠普的HP LaserJet 8100 Series PCL6为例. 1.从开始菜单选择“打印机和传真”. 2.鼠标右键“添加打印机”,然后单击“下一步”,选择“连接到这台计算机的本地打印机”,注意 ...
- 破解版windows 7(旗舰版)下安装并使用vagrant统一开发环境
参考百度经验:http://jingyan.baidu.com/article/5553fa82c158bb65a23934be.html,事先对win7进行破解后的三个文件进行还原,否则会导致vir ...
- C堆栈入门
原文:http://student.csdn.net/link.php?url=http://www.top-e.org%2Fjiaoshi%2Fhtml%2F427.html 格式和部分内容稍作修改 ...