在 Angular5 中获取本地存储对象函数时出错

Error to get localstorage object function in Angular5

我在使用 CircularJSON.stringify 时获取本地存储对象函数时遇到问题。 这是我的代码

//set localstorage data  
localStorage.setItem("client", CircularJSON.stringify(client)); // client is connection object 

//get localstorage data
let client = CircularJSON.parse(localStorage.getItem('client'));

在获取客户端对象时,只有变量显示并非所有函数

同时设置localstorage

同时获取localstorage

JSON.stringify() 将函数转换为 NULL 或从对象中删除键值对。一种方法可能是序列化整个函数并保存它。稍后检索时,反序列化函数。

不过我不建议在 LocalStorage 中保存函数。