优化存储
This commit is contained in:
parent
740ee6bc89
commit
60cd687575
@ -1,5 +1,5 @@
|
|||||||
const sessionCache = {
|
const sessionCache = {
|
||||||
set (key, value) {
|
set(key, value) {
|
||||||
if (!sessionStorage) {
|
if (!sessionStorage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -7,7 +7,7 @@ const sessionCache = {
|
|||||||
sessionStorage.setItem(key, value)
|
sessionStorage.setItem(key, value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get (key) {
|
get(key) {
|
||||||
if (!sessionStorage) {
|
if (!sessionStorage) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -16,23 +16,23 @@ const sessionCache = {
|
|||||||
}
|
}
|
||||||
return sessionStorage.getItem(key)
|
return sessionStorage.getItem(key)
|
||||||
},
|
},
|
||||||
setJSON (key, jsonValue) {
|
setJSON(key, jsonValue) {
|
||||||
if (jsonValue != null) {
|
if (jsonValue != null) {
|
||||||
this.set(key, JSON.stringify(jsonValue))
|
this.set(key, JSON.stringify(jsonValue))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getJSON (key) {
|
getJSON(key) {
|
||||||
const value = this.get(key)
|
const value = this.get(key)
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return JSON.parse(value)
|
return JSON.parse(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove (key) {
|
remove(key) {
|
||||||
sessionStorage.removeItem(key);
|
sessionStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const localCache = {
|
const localCache = {
|
||||||
set (key, value) {
|
set(key, value) {
|
||||||
if (!localStorage) {
|
if (!localStorage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ const localCache = {
|
|||||||
localStorage.setItem(key, value)
|
localStorage.setItem(key, value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get (key) {
|
get(key) {
|
||||||
if (!localStorage) {
|
if (!localStorage) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -49,22 +49,37 @@ const localCache = {
|
|||||||
}
|
}
|
||||||
return localStorage.getItem(key)
|
return localStorage.getItem(key)
|
||||||
},
|
},
|
||||||
setJSON (key, jsonValue) {
|
setJSON(key, jsonValue) {
|
||||||
if (jsonValue != null) {
|
if (jsonValue != null) {
|
||||||
this.set(key, JSON.stringify(jsonValue))
|
this.set(key, JSON.stringify(jsonValue))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getJSON (key) {
|
getJSON(key) {
|
||||||
const value = this.get(key)
|
const value = this.get(key)
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return JSON.parse(value)
|
return JSON.parse(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove (key) {
|
remove(key) {
|
||||||
localStorage.removeItem(key);
|
localStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
|
const cookie = {
|
||||||
|
set(key, data, expires) {
|
||||||
|
Cookies.set(key, data, { expires: expires })
|
||||||
|
},
|
||||||
|
set(key, data) {
|
||||||
|
Cookies.set(key, data)
|
||||||
|
},
|
||||||
|
remove(key) {
|
||||||
|
Cookies.remove(key)
|
||||||
|
},
|
||||||
|
get(key) {
|
||||||
|
Cookies.get(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
* 会话级缓存
|
* 会话级缓存
|
||||||
@ -73,5 +88,9 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* 本地缓存
|
* 本地缓存
|
||||||
*/
|
*/
|
||||||
local: localCache
|
local: localCache,
|
||||||
|
/**
|
||||||
|
* cookie存储
|
||||||
|
*/
|
||||||
|
cookie: cookie
|
||||||
}
|
}
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import Cookies from 'js-cookie'
|
|
||||||
|
|
||||||
export const cookie = {
|
|
||||||
set(key, data, expires) {
|
|
||||||
Cookies.set(key, data, { expires: expires })
|
|
||||||
},
|
|
||||||
set(key, data) {
|
|
||||||
Cookies.set(key, data)
|
|
||||||
},
|
|
||||||
remove(key) {
|
|
||||||
Cookies.remove(key)
|
|
||||||
},
|
|
||||||
get(key) {
|
|
||||||
Cookies.get(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const local = {
|
|
||||||
set(key, data) {
|
|
||||||
return localStorage.setItem(key, data)
|
|
||||||
},
|
|
||||||
remove(key) {
|
|
||||||
return localStorage.removeItem(key)
|
|
||||||
},
|
|
||||||
get(key) {
|
|
||||||
return localStorage.getItem(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user