简体   繁体   English

localStorage存储不正确

[英]localStorage not properly storing

I am trying to save a basic key and data to local storage. 我正在尝试将基本密钥和数据保存到本地存储。

I am doing this localStorage.setItem('theKey', 'theData'); 我正在执行此localStorage.setItem('theKey', 'theData');

For some reason when I check my localStorage in chrome I just see 'theData' stored as the key and no value with it. 出于某种原因,当我在chrome中检查我的localStorage时,我只会看到存储为密钥的“ theData”,但没有任何值。 Here is what I see: 这是我看到的:

在此处输入图片说明

Any ideas as to why this would be happening? 有什么想法为什么会这样? This is a react app does local storage perform differently with react? 这是一个React应用,本地存储的表现与React有区别吗?

Thank you 谢谢

It looks like the Key Value container is hidden in your console, try this. 您的控制台似乎隐藏了“键值”容器,请尝试此操作。

在此处输入图片说明

在此处输入图片说明

Open up the web console and run the command, localStorage.getItem('theKey') 打开Web控制台并运行命令localStorage.getItem('theKey')

If you still don't see it, try setting the key with window.localStorage.setItem('theKey', 'theData') 如果仍然看不到,请尝试使用window.localStorage.setItem('theKey', 'theData')设置密钥

将theData变量而不是'theData'保存为字符串值。

localStorage.setItem('theKey', theData);

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

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