utils

作者: lessonSam | 来源:发表于2020-06-15 22:55 被阅读0次
对于一个简单的方法去调用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);
}

相关文章

网友评论

      本文标题:utils

      本文链接:https://www.haomeiwen.com/subject/ohekxktx.html