如何使用localStorage进行数据存储?
- 内容介绍
- 文章标签
- 相关推荐
本文共计84个文字,预计阅读时间需要1分钟。
plaintext简化版本代码:const setStore=(name, content)=> { if (!name) return; if (typeof content !=='string') content=JSON.stringify(content); window.localStorage.setItem(name, content);};
gistfile1.txt/** * 存储localStorage */ export const setStore = (name, content) => { if (!name) return; if (typeof content !== 'string') { content = JSON.stringify(content); } window.localStorage.setItem(name, content); } /** * 获取localStorage */ export const getStore = name => { if (!name) return; return window.localStorage.getItem(name); } /** * 删除localStorage */ export const removeStore = name => { if (!name) return; window.localStorage.removeItem(name); }
本文共计84个文字,预计阅读时间需要1分钟。
plaintext简化版本代码:const setStore=(name, content)=> { if (!name) return; if (typeof content !=='string') content=JSON.stringify(content); window.localStorage.setItem(name, content);};
gistfile1.txt/** * 存储localStorage */ export const setStore = (name, content) => { if (!name) return; if (typeof content !== 'string') { content = JSON.stringify(content); } window.localStorage.setItem(name, content); } /** * 获取localStorage */ export const getStore = name => { if (!name) return; return window.localStorage.getItem(name); } /** * 删除localStorage */ export const removeStore = name => { if (!name) return; window.localStorage.removeItem(name); }

