having some data in localStorage, in my function first clearing the localstorage using clear() method and then adding one value to the localstorage. But its not clearing the old data
function() {
localStorage.clear();
localStorage.setItem('test', 'test');
}
最佳答案
你调用你的函数还是应该是一个自执行函数?
自执行示例:
(function(){
localStorage.clear();
localStorage.setItem('test', 'test');
})();
或作为箭头函数 (es6)
(() => {
localStorage.clear();
localStorage.setItem('test', 'test');
})()
关于javascript - 当您调用clear()然后在同一函数中设置一些本地存储值时不清除本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54780867/