2016-09-16 60 views
2

我正在使用Mobx创建可观察状态。如何将Mobx可观察对象转换为字符串

这是我的代码片断:

window.sessionStorage.setItem(createKey(key), JSON.stringify(state)) 

在上面的代码的“状态”目的是可观察的。 当我尝试将其转换成字符串,它给出了一个错误:

error:Cannot read property 'atom' of undefined

+0

你能告诉我们你的状态看起来如何?我会怀疑你只需要写'state.get()'而不是'JSON.stringify(state)'。 – Tholle

回答