31 lines
568 B
JavaScript
31 lines
568 B
JavaScript
/**
|
|
* 存储localStorage
|
|
*/
|
|
export const setStore = (name, content) => {
|
|
if (!name) return;
|
|
if (typeof content !== 'string') {
|
|
content = JSON.stringify(content);
|
|
}
|
|
window.localStorage.setItem(name, content);
|
|
}
|
|
|
|
/**
|
|
* 获取localStorage
|
|
*/
|
|
export const getStore = name => {
|
|
if (!name) return;
|
|
let v = window.localStorage.getItem(name);
|
|
if (v == null) {
|
|
return "";
|
|
}
|
|
return v;
|
|
}
|
|
|
|
/**
|
|
* 删除localStorage
|
|
*/
|
|
export const removeStore = name => {
|
|
if (!name) return;
|
|
window.localStorage.removeItem(name);
|
|
}
|