我在尝试从 localStorage 获取价值时得到 NaN。任何指针?在应用 Number 函数之前,该值为“488”。
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class PcUtilsService {
constructor() { }
// State Management
setSession(key: string, value: any): void {
localStorage.setItem(key, JSON.stringify(value));
}
getSession(key: string): number {
if (typeof window !== 'undefined') {
const value = localStorage.getItem(key) as string;
console.log('value', Number(value));
return Number(value);
}
}
clearSession(): void {
localStorage.clear();
}
}