vue操作本地存储


const ls = window.localStorage
const ss = window.sessionStorage


export const  LStorage= {
 getItem(key) {
  try {
   return JSON.parse(ls.getItem(key))
  } catch (err) {
   return null
  }
 },
 setItem(key, val) {
  ls.setItem(key, JSON.stringify(val))
 },
 clear() {
  ls.clear()
 },
 keys() {
  return ls.keys()
 },
 removeItem(key) {
  ls.removeItem(key)
 }
};



export const  SStorage= {
 getItem(key) {
  try {
   return JSON.parse(ss.getItem(key))
  } catch (err) {
   return null
  }
 },
 setItem(key, val) {
  ss.setItem(key, JSON.stringify(val))
 },
 clear() {
  ss.clear()
 },
 keys() {
  return ss.keys()
 },
 removeItem(key) {
  ss.removeItem(key)
 }
};

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM