请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

store.subscribe放在constructor中引起无法对尚未装入的组件调用setState问题

Can’t call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to this.state directly or define a state = {}; class property with the desired state in the TodoList component.
图片描述
图片描述

图片描述

请问这是什么原因呢?

正在回答

3回答

https://img1.sycdn.imooc.com//szimg/5e99b585098c902503260084.jpg

https://img1.sycdn.imooc.com//szimg/5e99b585089301ed06250209.jpg

兄弟,我这边按照你的写法,是没问题的

你是不是哪里写错没看到

0 回复 有任何疑惑可以回复我~
  • 提问者 九月1004 #1
    非常感谢!
    回复 有任何疑惑可以回复我~ 2020-04-23 09:44:29
  • 我照着楼主的写法,清了缓存没用,input第一次变化还是会有一次报错。后面再变化就正常了
    回复 有任何疑惑可以回复我~ 2020-07-13 15:06:32
FrankyShyShy 2020-07-23 18:06:07

应该是开启严格模式才会报的错,感觉这个监听变化的方法其实也是应该放在componentDidMount里面,因为监听后会进行setState的操作,setState要在组件挂载后才能执行,所以放在componentDidMount里才对


0 回复 有任何疑惑可以回复我~
提问者 九月1004 2020-04-23 09:45:03

缓存问题,我清理了下缓存就可以了,谢谢

0 回复 有任何疑惑可以回复我~
  • 提问者 九月1004 #1
    确实没什么问题
    回复 有任何疑惑可以回复我~ 2020-04-23 09:45:29
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号