需求:
在组件中提交一份表单,表单填写途中切换到其他页面(组件),再回来时之前填的信息默认展示。
思路:在componentWillUnmount中将表单中的数据保存到localstorage中,在componentDidMount时从localstorage中取出。
问题:componentWillUnmount中的代码不执行。无法存到localstorage中。
需求:
在组件中提交一份表单,表单填写途中切换到其他页面(组件),再回来时之前填的信息默认展示。
思路:在componentWillUnmount中将表单中的数据保存到localstorage中,在componentDidMount时从localstorage中取出。
问题:componentWillUnmount中的代码不执行。无法存到localstorage中。
4 回答1.7k 阅读
2 回答1.1k 阅读✓ 已解决
2 回答2.6k 阅读
1 回答962 阅读✓ 已解决
1 回答689 阅读✓ 已解决
2 回答852 阅读✓ 已解决
2 回答1k 阅读
哪有那么麻烦。
用一个state值记录这个表单就可以了。
切回来的时候,就相当于编辑功能。