一个面包屑导航功能,单独封装了一个组件。在关闭当前tab的时候,需要跳转至上一个path。
我考虑在父级调用这个组件时将history
传过去,然后就可以通过history.push()
进行跳转。
这时我想到数据持久化的问题,便打算将history
保存至localStorage
,
但是因为JSON.stringify(function...)
会将方法体过滤:
ECMASCript官方也特意强调了这一点:
It does not attempt to impose ECMAScript’s internal data representations on other programming languages. Instead, it shares a small subset of ECMAScript’s textual representations with all other programming languages.
所以想问一下:
- 如何将方法体存入
localStorage
? - 如果不采取存入
localStorage
的方法,那么有什么办法可以长时间保存此类数据?
stringify的时候检测到某个value是function的时候tostring一下?但问题还是很多的