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.
tanghe-report/report-ui/src/utils/storage.js

61 lines
1.1 KiB
JavaScript

3 years ago
/*
* @Descripttion:
* @version:
* @Author: qianlishi
* @Date: 2021-12-11 14:48:27
* @LastEditors: qianlishi
* @LastEditTime: 2021-12-13 10:16:49
*/
3 years ago
import Cookies from 'js-cookie'
export function setCookie(k, v) {
3 years ago
if(typeof(v) == "undefined" || v == null){
return;
}
3 years ago
let val = v;
3 years ago
if(typeof(v) == "object"){
val = JSON.stringify(v);
}
Cookies.set(k, val)
Cookies.get(k, val)
}
export function getCookie(k) {
3 years ago
let val = Cookies.get(k);
3 years ago
try{
//如果是number boolean jsonstring是不会报错的
return JSON.parse(val);
}catch(e){
return val;
}
}
export function delCookie(k) {
3 years ago
Cookies.remove(k);
}
export function setStorageItem(k, v) {
if(typeof(v) == "undefined" || v == null){
return;
}
3 years ago
let val = v;
3 years ago
if(typeof(v) == "object"){
val = JSON.stringify(v);
}
localStorage.setItem(k, val)
}
export function getStorageItem(k) {
3 years ago
let val = localStorage.getItem(k);
3 years ago
try{
//如果是number boolean jsonstring是不会报错的
return JSON.parse(val);
}catch(e){
return val;
}
}
export function delStorageItem(k) {
localStorage.removeItem(k);
}