localStorage控制

let localStorage = window.localStorage;
/**
  * 读取存储
  */
function getValue(key, defaultValue) {
  var value = localStorage[key];
  if (value) {
    return JSON.parse(value)
  } else {
    return defaultValue
  }
}

/**
  * 写入存储
  */
function setValue(key, value) {
  localStorage[key] = JSON.stringify(value)
}

/**
  * 删除存储
  */
function delValue(key) {
  return delete localStorage[key]
}  

posted @ 2017-08-03 17:01  ding0304  阅读(155)  评论(0)    收藏  举报