local.ts 416 B

123456789101112131415161718192021
  1. // 封装本地存储
  2. // 存
  3. export const setLocal = (key: any, value: any) => {
  4. localStorage.setItem(key, JSON.stringify(value))
  5. }
  6. // 取
  7. export const getLocal = (key: any) => {
  8. return JSON.parse(localStorage.getItem(key))
  9. }
  10. // 删除
  11. export const removeLocal = (key: any) => {
  12. localStorage.removeItem(key)
  13. }
  14. // 清空
  15. export const clearLocal = () => {
  16. localStorage.clear()
  17. }