/**
* storage 二次封装
*/
// config.js
export default {
namespace: 'manager'
}
// storage.js
import config from './../config'
export default {
setItem(key, val) {
let storage = this.getStorage()
storage[key] = val
window.localStorage.setItem(config.namespace, JSON.stringify(storage))
},
getItem(key) {
return this.getStorage()[key]
},
clearItem(key) {
let storage = this.getStorage()
delete storage[key]
window.localStorage.setItem(config.namespace, JSON.stringify(storage))
},
clearAll() {
window.localStorage.clear()
},
getStorage() {
let storage = window.localStorage.getItem(config.namespace) || '{}'
return JSON.parse(storage)
}
}
storage 二次封装
于 2023-02-01 16:11:45 首次发布