perf:发布版本1.0.2
This commit is contained in:
42
src/utils/Storage.js
Normal file
42
src/utils/Storage.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import Common from "./Common";
|
||||
|
||||
///////////////////////////////////////// 用户token
|
||||
|
||||
/**
|
||||
* 保存用户token
|
||||
* @param token
|
||||
*/
|
||||
const saveUserToken = (token) => {
|
||||
save('token', token);
|
||||
};
|
||||
|
||||
const getUserToken = () => {
|
||||
return get('token') || '';
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
const save = (key, value) => {
|
||||
localStorage.setItem(key, JSON.stringify({data: value}));
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* @param key
|
||||
* @returns {string}
|
||||
*/
|
||||
const get = (key) => {
|
||||
return Common.parseJSON(localStorage.getItem(key), {data: ""}).data;
|
||||
};
|
||||
|
||||
///////////////////////////////////////// 导出模块
|
||||
|
||||
export default {
|
||||
save,
|
||||
get,
|
||||
saveUserToken,
|
||||
getUserToken,
|
||||
};
|
||||
Reference in New Issue
Block a user