解除wx:key Now you can provide attr “wx:key“ for a “wx:for“ to improve performance.

Encountered a warning in the actual development process : Now you can provide attr "wx:key" for a "wx:for" to improve performance.
Searching for information online and viewing official documents found that the reason is roughly as follows:
 
official explanation:
wx:key
if list The position of the item in the list will be dynamically changed or new items are added to the list, and the items in the list are expected to maintain their own characteristics and status (such as the input content in <input/>, the selected state of <switch/>), you need Use wx:key to specify the unique identifier of the item in the list.

Online information:
The value of wx:key is provided in two forms
1. wx:key="property" where property represents a property of item in the array of the for loop, and the value of the property needs to be the only string in the list Or numbers, and cannot be changed dynamically. Similar to the key value
2, wx:key="*this" of the dictionary , the reserved keyword *this represents the item itself in the for loop. This representation requires the item itself to be a unique string or number, such as:
when data When the change triggers the rendering layer to re-render, the components with keys will be corrected, and the framework will ensure that they are reordered instead of re-created to ensure that the
components maintain their own state and improve the efficiency of the list rendering.
 
If wx:key is not added:
<block wx:for-items="{ {userInfoList}}" >, a warning will appear: Now you can provide attr "wx:key" for a "wx:for" to improve performance. If You know that the list is static, or you don’t need to pay attention to its order, you can choose to ignore it.
 
It is recommended that each item in the array be managed by adding a uniquely identified property, so that the warning can be removed. If reserved keywords are used, it seems that the displayed items are all the last
<block wx:for-items="{ { userInfoList}}" wx:key="userInfoListId" or wx:key="

Guess you like

Origin blog.csdn.net/m0_37218227/article/details/107045007