ng g class widget/script/session ng g class common/app-common // 修改session为小写 export class sesssion { static set(key: string, value: any) { sessionStorage.setItem(key, JSON.stringify(value)); } static get(key: string) { const d = sessionStorage.getItem(key); if (!d) { return d; } return !!d ? JSON.parse(d) : ''; } static remove(key: string) { sessionStorage.clear(); } static count() { return sessionStorage.length; } } import {sesssion} from '../widget/script/session'; export class AppCommon { // 用户信息 private static _userInfo; static get userInfo() { if (!this._userInfo) { this._userInfo = sesssion.get('_userInfo'); } return this._userInfo; } static set userInfo(value) { this._userInfo = value; sesssion.set('userInfo', value); } }