vue项目常用之三:window.localStorage持久化存储数据封装

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)
}

 

vue项目常用之三:window.localStorage持久化存储数据封装

上一篇:WebApi框架搭建(一)集成Swagger


下一篇:nu-book/zxing-cpp在windows7下的编译