Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
主要分为两种情况:
比如在开启隐身模式情况下,
localStorage
的大小被设置为0,这样使用setItem
去存储数据是会报错的,采取的是通过检测该种情况,然后采取用一个缓存对象去代替内存,并重写setItem
,getItem
等 API 进行hack的方式解决。在正常情况下,浏览器是有大概 5 M 的
localStorage
使用空间(不同浏览器不同),如果存的东西比较多,就存在超出内存空间的情况,这种情况只能通过每一次执行setItem
的时候去判断是不是超出内存限制了,这里使用了兼容的判断方式,不只是通过e.name
去判断,如果出现这种错误就给用户一个提示,这里还可以继续完善就是可以让用户传一个回调,在超出内存限制的时候可以去删除一些不重要的数据进而释放空间(当然也可以直接 clear)。