fix: 处理本地存储序列化的问题

This commit is contained in:
奔跑的面条 2023-01-13 16:14:42 +08:00
parent 279f414db0
commit cbf541282a
2 changed files with 5 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import { JSONStringify, JSONParse } from './utils'
/**
* *
* @param k
@ -6,7 +8,7 @@
*/
export const setLocalStorage = <T>(k: string, v: T) => {
try {
window.localStorage.setItem(k, JSON.stringify(v))
window.localStorage.setItem(k, JSONStringify(v))
} catch (error) {
return false
}
@ -20,7 +22,7 @@ export const setLocalStorage = <T>(k: string, v: T) => {
export const getLocalStorage = (k: string) => {
const item = window.localStorage.getItem(k)
try {
return item ? JSON.parse(item) : item
return item ? JSONParse(item) : item
} catch (err) {
return item
}

View File

@ -295,7 +295,7 @@ export const setKeyboardDressShow = (keyCode?: number) => {
* * JSON序列化 undefined
* @param data
*/
export const JSONStringify = (data: object) => {
export const JSONStringify = <T>(data: T) => {
return JSON.stringify(
data,
(key, val) => {