在执行localStorage.setItem('user',some string here
)时,我在iphone的安装上遇到此错误:
Error: The quota has been exceeded.
setItem@[native code]
非私密模式!请帮助了解其他情况可以使localStorage无法正常工作。
答案 0 :(得分:1)
实际上它是私人模式。看起来默认情况下在新的iphone上启用。
答案 1 :(得分:0)
我创建了这个类来帮助绕过隐私浏览。但是,当您刷新浏览器时,存储将会被吹走。
const data = {};
let hasLocalStorage = false;
if (localStorage) {
try {
const x = 'storageTest';
localStorage.setItem(x, x);
localStorage.removeItem(x);
hasLocalStorage = true;
} catch (e) {
hasLocalStorage = false;
}
}
class StorageUtilities {
setItem(key, value) {
if (hasLocalStorage) {
localStorage.setItem(key, value);
} else {
data[key] = value;
}
}
getItem(key) {
if (hasLocalStorage) {
return localStorage.getItem(key);
}
return data[key];
}
removeItem(key) {
if (hasLocalStorage) {
localStorage.removeItem(key);
} else {
data[key] = null;
}
}
}
const storageUtilities = new StorageUtilities();
export default storageUtilities;