vue项目中使用storage本地存储封装
作者:互联网
storage.js
// 存储
const _setStorage = (key, value)=>{
sessionStorage.setItem(key, JSON.stringify(value));
}
// 查找
const _getStorage = (key)=>{
return JSON.parse(sessionStorage.getItem(key));
}
const _getForIndexStorage = (index)=>{
return sessionStorage.key(index)
}
// 删除
const _removeStorage = (key)=>{
sessionStorage.removeItem(key);
}
// 清空
const _removeAllStorage = ()=>{
sessionStorage.clear();
}
export default {
_removeAllStorage,
_removeStorage,
_getForIndexStorage,
_getStorage,
_setStorage,
}
vue页面使用先引入后使用
标签:setStorage,vue,封装,index,sessionStorage,storage,key,const 来源: https://blog.csdn.net/JackieDYH/article/details/110824169