/**
* Storage二次封装
*/
import config from './../config'
export default {
setItem(key,val){
let storage = this.getStroage();
storage[key] = val;
window.localStorage.setItem(config.namespace,JSON.stringify(storage));
},
getItem(key){
return this.getStroage()[key]
},
getStroage(){
return JSON.parse(window.localStorage.getItem(config.namespace) || "{}");
},
clearItem(key){
let storage = this.getStroage()
delete storage[key]
window.localStorage.setItem(config.namespace,JSON.stringify(storage));
},
clearAll(){
window.localStorage.clear()
}
}
二次封装storage, 避免手动多次写json.pase和stringfy, 同时避免一个域名下多项目本地变量名冲突
最新推荐文章于 2025-08-23 02:53:08 发布