db.js

作者: 泠泉 | 来源:发表于2019-04-24 09:53 被阅读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)
      }
    }
    
    

    相关文章

      网友评论

          本文标题:db.js

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