You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
972 B
JavaScript
53 lines
972 B
JavaScript
3 years ago
|
import Cookies from 'js-cookie'
|
||
|
export function setItem(k, v) {
|
||
|
if(typeof(v) == "undefined" || v == null){
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var val = v;
|
||
|
if(typeof(v) == "object"){
|
||
|
val = JSON.stringify(v);
|
||
|
}
|
||
|
Cookies.set(k, val)
|
||
|
Cookies.get(k, val)
|
||
|
}
|
||
|
|
||
|
export function getItem(k) {
|
||
|
var val = Cookies.get(k);
|
||
|
try{
|
||
|
//如果是number boolean jsonstring是不会报错的
|
||
|
return JSON.parse(val);
|
||
|
}catch(e){
|
||
|
return val;
|
||
|
}
|
||
|
}
|
||
|
export function delItem(k) {
|
||
|
Cookies.remove(k);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
export function setStorageItem(k, v) {
|
||
|
if(typeof(v) == "undefined" || v == null){
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var val = v;
|
||
|
if(typeof(v) == "object"){
|
||
|
val = JSON.stringify(v);
|
||
|
}
|
||
|
localStorage.setItem(k, val)
|
||
|
}
|
||
|
|
||
|
export function getStorageItem(k) {
|
||
|
var val = localStorage.getItem(k);
|
||
|
try{
|
||
|
//如果是number boolean jsonstring是不会报错的
|
||
|
return JSON.parse(val);
|
||
|
}catch(e){
|
||
|
return val;
|
||
|
}
|
||
|
}
|
||
|
export function delStorageItem(k) {
|
||
|
localStorage.removeItem(k);
|
||
|
}
|