简体   繁体   English

无法在 session 存储中存储 object

[英]unable to store object in session Storage

在此处输入图像描述

In this image you can see I am getting an array of objects and at Zero position I am getting some objects Now my task is to store these objects in sessionStorage.在这张图片中,您可以看到我得到了一个对象数组,并且在零时 position 我得到了一些对象现在我的任务是将这些对象存储在 sessionStorage 中。

sessionStorage.setItem("mytime",JSON.stringify(data[0]));

When I am checking in sessionStorageis showing an Empty object.当我签入 sessionStorage 时,显示的是 Empty object。

There is a difference b/w sessionStorage and localStorage.黑白 sessionStorage 和 localStorage 是有区别的。

The sessionStorage is available only for that particular session ie if a browser is reloaded, you will no longer be able to access the data. sessionStorage仅适用于特定的 session 即,如果重新加载浏览器,您将无法再访问数据。 However, localStorage is persistent and will be available until you explicitly remove it.但是, localStorage是持久的,并且在您明确删除它之前一直可用。

If the value is empty, you need to check the value of data[0] .如果值为空,则需要检查data[0]的值。

localStorage.setItem('mytest', 'Check the local storage console');
console.log(localStorage.getItem('mytest'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM