对于一个简单的方法去调用store 库显得麻烦还占内存 不如自己手撕代码
export const setStore = (name, content) => {
if(!name) return;
if(typeof content != 'string') {
content = JSON.stringify(content)
}
window.localStorage.setItem(name, content)
}
// 获取
export const getStore = name => {
if(!name) return;
return window.localStorage.getItem(name);
}
// 删除
export const removeStore = name => {
if(!name) return;
window.localStorage.removeItem(name);
}
export const setStore = (name, content) => {
if(!name) return;
if(typeof content != 'string') {
content = JSON.stringify(content)
}
window.localStorage.setItem(name, content)
}
// 获取
export const getStore = name => {
if(!name) return;
return window.localStorage.getItem(name);
}
// 删除
export const removeStore = name => {
if(!name) return;
window.localStorage.removeItem(name);
}
网友评论