Warning: Each child in an array or iterator should have a unique "key" prop. Check the top-level render call using
. See https://fb.me/react-warning-keys for more information.
出現(xiàn)的原因:
這個(gè)是和react的dom-diff算法相關(guān)的叠聋。react對dom做遍歷的時(shí)候乔询,會(huì)根據(jù)data-reactid生成虛擬dom樹床绪。如果你沒有手動(dòng)的添加unique constant key的話,react是無法記錄你的dom操作的。它只會(huì)在重新渲染的時(shí)候间雀,繼續(xù)使用相應(yīng)dom數(shù)組的序數(shù)號(就是array[index]這種)來比對dom樹。
更改后的代碼如下:
加入key值即可