mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
fix: 处理本地存储序列化的问题
This commit is contained in:
parent
279f414db0
commit
cbf541282a
@ -1,3 +1,5 @@
|
|||||||
|
import { JSONStringify, JSONParse } from './utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 存储本地会话数据
|
* * 存储本地会话数据
|
||||||
* @param k 键名
|
* @param k 键名
|
||||||
@ -6,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
export const setLocalStorage = <T>(k: string, v: T) => {
|
export const setLocalStorage = <T>(k: string, v: T) => {
|
||||||
try {
|
try {
|
||||||
window.localStorage.setItem(k, JSON.stringify(v))
|
window.localStorage.setItem(k, JSONStringify(v))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -20,7 +22,7 @@ export const setLocalStorage = <T>(k: string, v: T) => {
|
|||||||
export const getLocalStorage = (k: string) => {
|
export const getLocalStorage = (k: string) => {
|
||||||
const item = window.localStorage.getItem(k)
|
const item = window.localStorage.getItem(k)
|
||||||
try {
|
try {
|
||||||
return item ? JSON.parse(item) : item
|
return item ? JSONParse(item) : item
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ export const setKeyboardDressShow = (keyCode?: number) => {
|
|||||||
* * JSON序列化,支持函数和 undefined
|
* * JSON序列化,支持函数和 undefined
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
export const JSONStringify = (data: object) => {
|
export const JSONStringify = <T>(data: T) => {
|
||||||
return JSON.stringify(
|
return JSON.stringify(
|
||||||
data,
|
data,
|
||||||
(key, val) => {
|
(key, val) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user