IE 下使用localstorage

2019-10-23  本文已影响0人  IamaStupid

不知道为什么有的IE11浏览器不支持localStorage,在此记录一下

  1. ie11 使用localstorage,不支持,不得不做一些判断,比如
if(window.localStorage && typeof window.localStorage.clear === 'function'){
    window.localStorage.clear();
}

if(window.localStorage&&window.localStorage['MY_ANYCHAT_STORE_STATE']){
  state = JSON.parse(window.localStorage['MY_ANYCHAT_STORE_STATE']);
}

if(window.localStorage && typeof window.localStorage.setItem === 'function'){
    window.localStorage.setItem('MY_ANYCHAT_STORE_STATE',JSON.stringify(store.getState()));
}
ie11-localstorage.PNG
上一篇 下一篇

猜你喜欢

热点阅读