报错:Failed to execute 'setItem' on 'Storage': Setting the value of 'address' exceeded the quota.
场景:对常用地址做本地存储,减少后端请求
异常:在localStorage里面没有找到存储的数据,刷新页面重新请求接口
排查:浏览器console输出报Failed to execute 'setItem' on 'Storage': Setting the value of 'address' exceeded the quota.查找资料发现是超出单条最大长度导致,
资料查询:发现此问题是超出了localStorage的最大长度导致的,另查找资料发现最大存储为5M;
撰写代码:清除存储数据的null和空字符串等无用数据,节省存储占用;问题暂时解决
反思:在使用本地存储的时候清除不必要的数据,防止出现空数据占用空间
获取最大存储的方法之一使用累加的方法,累加方法如下,可以验证你的剩余存储空间:
let str = "1234567890";
localStorage.setItem("str",str)
let timer = setInterval(()=>{
str+=localStorage.getItem("str");
console.log(str.length/(1024*1024),str.length);
localStorage.setItem("str",str);
}catch (e) {
clearInterval(timer)
},20)
报错:Failed to execute 'setItem' on 'Storage': Setting the value of 'address' exceeded the quota.场景:对常用地址做本地存储,减少后端请求异常:在localStorage里面没有找到存储的数据,刷新页面重新请求接口排查:浏览器console输出报Failed to execute 'setItem' on 'Storage': Setting the value of 'address' exceeded
Web
Storage
网络存储
HTML5
的Web
Storage
网络存储是指网络应用程序用于在网络浏览器存储方法和通讯协议,支持持久数据存储,类似于Cookie,以及window-local存储。网络存储又分为
localStorage
本地存储和
session
Storage
会话存储。
localStorage
本地存储
localStorage
用于持久化的本地存储,除非主动删除数据,否则数据永远不
在vue当中,我为了页面可以返回,存了好几张图片信息,但是发现
使用
session
Storage
是有限制,最多5M,如果溢出的话实际上是没有存进去的,所以也是不能调用
报错
了。
报错
如下:
怎么办,怎么让照片回退的时候还
报错
着?
使用
session
Storage
超过大小限制
Failed
to
execute
'
set
Item
' on '
Storage
':
Set
ting
the
value
of 'feature' exceeded the
quota
.
const add
Session
Storage
= (key, store
Obj
) => {
//定义一个前缀,表示只删除自己定义的缓存
const...
本文主要介绍本地存储的基本使用,以及它和 Cookie、
Session
Storage
的区别。
简单回顾 Cookie
在
HTML5
之前,本地存储数据一般是通过 Cookie 来完成的。我们可以把 Cookie 理解为一个长度有限的字符串,服务端和客户端都能读写这个字符串,并且每次请求时,都会把 Cookie 发送到服务端。
通常,我们可以利用这个字符串来保存用户名、密码等数据,来实现记...
在学习vue的时候要用到前台的缓存
session
Storage
,于是使用了如下方式存储
window.
session
Storage
.
set
Item
(activePath)
但是却在控制台出现了如下的
报错
信息
vue.runtime.esm.js?2b0e:1888 TypeError:
Failed
to
execute
'
set
Item
' on '
Storage
': 2 arguments required, but only 1 present.
在百度上将错误信息搜索了一下,
这个文件封装的是图片压缩方法:取名api.js
//base64转码(压缩完成后的图片为base64编码,这个方法可以将base64编码转回file文件)
function dataURLtoFile(dataurl, name) {
var arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.le
DOMException:
Failed
to
execute
'
set
Item
' on '
Storage
':
Set
ting
the
value
of 'widgetCacheData' exceeded the
quota
.
在使用
session
Storage
做缓存处理时,报了如上的错误提示,经查是
session
Storage
对大小是有限制的,所以要进行try catch,500KB左右的东西保存起来就会令到Resources变卡,2M左右就可以令到Resources卡死,操作不了,5M就到了Chro
localStorage
是
HTML5
中引入的一种存储数据的机制。它允许在浏览器中存储键值对,并且能够跨会话保持数据。这意味着用户在关闭浏览器之后,数据仍然会保存在本地,下次用户访问网站时,数据仍然可用。
localStorage
对象是全局的,因此可以在页面中的任何位置使用它。要使用
localStorage
,可以使用以下方法:
- 存储数据:
localStorage
.
set
Item
(key,
value
);
- 获取数据:
localStorage
.get
Item
(key);
- 删除数据:
localStorage
.remove
Item
(key);
其中,key 是存储的键,
value
是存储的值。注意,存储的值必须是字符串类型,如果存储其他类型的数据,需要将其转换成字符串类型。
需要注意的是,
localStorage
有一些限制:
- 每个域名只能使用 5MB 的存储空间。
- 存储的数据只能是字符串类型,如果需要存储其他类型的数据,需要进行转换。
-
localStorage
是同步的,如果存储或获取数据的过程比较耗时,可能会影响页面的性能。
-
localStorage
只能在同一浏览器中共享数据,不同浏览器之间的数据是独立的。
upstream prematurely closed connection while reading response header from upstream
CSDN-Ada助手: