-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
页面时间更新不正确 #1
Comments
你清理浏览器缓存后再试试 |
是的,我也是发现这个问题,删除comment后 时间显示有停滞,等5秒时间会恢复,但是,时间显示体验看起来不好。 不知道是因为什么引起的。 |
+1 |
我没有遇到这个问题,我遇到的是删除前面的评论,最后一条评论的时间会变成他的前一条评论的时间。刷新后变回去了 |
解决方案:在commentList中设置 key={comment.time}。 应该是key的问题。 在commentList中遍历comment列表的时候。commentList中传入的key默认是给的key={i}。 <Comment
comment={comment}
key={i}
index={i}
onDeleteComment={this.handleDeleteComment.bind(this)} /> 因为这个key,删除一个评论之后它的key值排列并没有变只是最后一个不见了。所以对应关系可能有问题。 key 必须是每个元素唯一的标识。将key设置为time。这个值是跟对应的数据唯一且固定对应的。key={comment.time}。就不会出现对应关系错误导致的内部状态错误的问题了。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
首先非常感谢你的教程!!
我按照你说的一步步来的时候,只是把commnet unshift到列表里面,因为我想按时间倒序排列评论。
结果出现了最新插入的那一条的时间是上一条的时间,页面5秒之后刷新才会显示正确的时间。
而且我打印log到控制台,更诡异了,出现的却是comments列表的最后一条,而不是我新插入的那条(但是界面却更新了),请问这个是怎么回事?谢谢
上面这段话在友言里面有敏感字,也是醉了我录了截图:
The text was updated successfully, but these errors were encountered: