1. 程式人生 > >html 快取的用法

html 快取的用法

//存如快取
function cl(msg){
	if(window.localStorage){
		localStorage.setItem("usermsg",msg);
	}else{
		Cookie.write("usermsg",msg);
	}
}
//從快取中取出
var str = window.localStorage?localStorage.getItem("usermsg"):Cookie.read("usermsg");
//存如快取
if(window.localStorage){
	localStorage.setItem("usermsg",JSON.stringify(response.data));
}else{
	Cookie.write("usermsg",JSON.stringify(response.data));
}
//從快取中取出
var str = window.localStorage?localStorage.getItem("usermsg"):Cookie.read("usermsg");
console.log(JSON.parse(str));//轉化成json