export const setItem = (name, value) => {
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  window.localStorage.setItem(name, value)
}

export const getItem = name => {
  const data = window.localStorage.getItem(name)
  try {
    return JSON.parse(data)
  } catch (err) {
    return data
  }
}

export const removeItem = name => {
  window.localStorage.removeItem(name)
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2022-02-03
  • 2021-07-05
  • 2022-12-23
  • 2021-08-04
  • 2022-03-04
  • 2021-12-03
相关资源
相似解决方案