db.js

2019-04-24  本文已影响0人  泠泉
const localStorage = window.sessionStorage
const JSON = window.JSON

export default {
  get (name) {
    let value = localStorage.getItem(name)
    if (/^\{.*\}$/.test(value)) value = JSON.parse(value)
    return value
  },
  set (name, value) {
    if (typeof value === typeof {}) value = JSON.stringify(value)
    return localStorage.setItem(name, value)
  },
  remove (name) {
    return localStorage.removeItem(name)
  }
}

上一篇下一篇

猜你喜欢

热点阅读