最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】ReactJS中如何操作sessionStorage或localStorage

ReactJS crifan 10781浏览 0评论

折腾:

【未解决】ReactJS页面是否支持传入url和其他登录信息等参数

期间,需要去:

Reactjs中,操作和处理sessionStorage后localStorage

react js session storage

javascript – Initiliaze & using sessionStorage in React? – Stack Overflow

window.sessionStorage.setItem(“key”, “value”);

window.sessionStorage.getItem(“key”);

Window.sessionStorage – Web APIs | MDN

reactjs – How to get to Web API’s sessionStorage object in React – Stack Overflow

conorhastings/redux-session-storage: redux middleware for recording redux actions for a particular session to session storage

Local Storage in React – RWieruch

React mixin for caching state in sessionStorage across mounts.

Persistent State of ReactJS Component – Minko Gechev’s blog

【总结】

不用第三方库,Web API内置就支持sessionStorage或localStorage

客户端浏览器直接用:sessionStorage

服务器端用:window.sessionStorage

代码:

window.sessionStorage.setItem(‘sessionUserId’, ‘sessionCrifan’);
console.log(‘read out sessionStorage: sessionUserId=’, window.sessionStorage.getItem(‘sessionUserId’));

效果:

转载请注明:在路上 » 【已解决】ReactJS中如何操作sessionStorage或localStorage

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.186 seconds, using 22.07MB memory