最新消息:20190529 VPS服务器已从腾讯云香港换为Vultr新加坡,主题仍用朋友推荐的大前端D8

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

ReactJS crifan 1744浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
62 queries in 0.084 seconds, using 18.81MB memory