warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance.

小程序开发过程中在写for循环的时候会出现如下报错

warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance.
<block wx:for="{{imgUrls}}" wx:key="swiper">
      <swiper-item>
          <image src=‘{{item}}‘ class=‘slide-image‘ width="355" height="150"></image>
      </swiper-item>
</block>

小程序API文档表示:

wx:key

如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 <input/> 中的输入内容,<switch/> 的选中状态),需要使用 wx:key 来指定列表中项目的唯一的标识符。

wx:key 的值以两种形式提供

  1. 字符串,代表在 for 循环的 array 中 item 的某个 property,该 property 的值需要是列表中唯一的字符串或数字,且不能动态改变。
  2. 保留关键字 *this 代表在 for 循环中的 item 本身,这种表示需要 item 本身是一个唯一的字符串或者数字,如:

当数据改变触发渲染层重新渲染的时候,会校正带有 key 的组件,框架会确保他们被重新排序,而不是重新创建,以确保使组件保持自身的状态,并且提高列表渲染时的效率。

如不提供 wx:key,会报一个 warning, 如果明确知道该列表是静态,或者不必关注其顺序,可以选择忽略。

于是......在block上加上wx:key属性就不报错了

<block wx:for="{{imgUrls}}">
      <swiper-item>
          <image src=‘{{item}}‘ class=‘slide-image‘ width="355" height="150"></image>
      </swiper-item>
</block>

原文地址:https://www.cnblogs.com/leiting/p/8414682.html

时间: 2024-08-25 03:14:24

warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance.的相关文章

wx:key

在实际开发过程中遇到 warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance. 上网查找资料与查看官方文档发现原因大致如下: 官方解释: wx:key 如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 <input/> 中的输入内容,<switch/> 的选中状态),需要使用 wx:k

Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)

当你的selenium WebDriver 启动IE11报这个错时:Unable to find element on closed window (WARNING: The server did not provide any stacktrace information),通过Google解决了:Required Configuration:For IE 11 only, you will need to set a registry entry on the target computer

微信小程序wx:key以及wx:key=&quot; *this&quot;详解:

今天写微信小程序无意中看到控制台给出了这样一行提示: 求解百度才知道,给大家分享一下: 1.wx:for定义 官方文档:在组件上使用 wx:for 控制属性绑定一个数组,即可使用数组中各项的数据重复渲染该组件. 默认数组的当前项的下标变量名默认为 index,数组当前项的变量名默认为 item 人话:根据已有数据来迭代生成组件的一个方法.学前端的同学肯定不会陌生了,V-for.ng-repeat都是一样的原理,可是在这里为什么会报错呢,往下看 2.wx:key定义 官方文档:如果列表中项目的位置

Android - Warning:Not annotated parameter overrides @NonNull parameter

Warning:Not annotated parameter overrides @NonNull parameter 本文地址:http://blog.csdn.net/caroline_wendy Warning:The @NonNull annotation can be used to indicate that a given parameter can not be null. "@NonNull"的含义是注释非空,如果出现以上警告,就表明参数应该有非空标注: 如添加:

warning:deprecated conversion from string constant to &#39;char *&#39;

warning:deprecated conversion from string constant to 'char *' 解决方案 #include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } int main() { fuc("hello"); } Linux 环境下当GCC版本比较高时,编译代码可能出现的问题. 主要原因是: char * 指针

【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo

1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be consistent [环境描述] msyql5.6.14 [报错信息] mysql的slave启动时,error.log中出现Warning警告: [Warning] Slave SQL: If a crash happensthis configuration does not guarantee tha

Windows下Git使用报错:warning:LF will be replaced by CRLF in &#215;&#215;&#215;&#215;.&#215;&#215;

Windows下Git使用报错: warning:LF will be replaced by CRLF in ××××.××(文件名) The file will have its original line ending in your working directory. 翻译: 在xxx.xx文件中LF将被CRLF替换. 在工作区(working directory)里,这个文件将会保持它原本的换行符.(line ending:行尾,换行) 注解:           LF:Line F

Warning: Cannot send session cookie – headers already sent…

相信大多数人在写PHP代码的时候,都遇到过类似 "Warning: Cannot send session cookie – headers already sent…“或者”Cannot add/modify header information – headers already sent…" 这样的Warning提示.下面我们就来看看发生这个Warning的原因及解决方案. 函数 header(),setcookie() 和 session 函数需要在输出流中增加头信息.但是头信

[转帖]Warning:detected &quot;cgroupfs&quot; as the Docker cgroup driver. The recommended driver is &quot;systemd&quot;.

Warning:detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". https://www.cnblogs.com/ExMan/p/11613812.html 执行kubeadm init集群初始化时遇到: [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Do