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 的值以两种形式提供
- 字符串,代表在 for 循环的 array 中 item 的某个 property,该 property 的值需要是列表中唯一的字符串或数字,且不能动态改变。
- 保留关键字
*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>
warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance.的更多相关文章
- 微信小程序开发warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance
用微信官方的模板发现突然报了这个warning,检查原因: 官方解释: wx:key 如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 <i ...
- 小程序开发-Now you can provide attr "wx:key" for a "wx:for" to improve performance
Now you can provide attr "wx:key" for a "wx:for" to improve performance 是一个关于性能优 ...
- Now you can provide attr "wx:key" for a "wx:for" to improve performance. 微信小程序警告
Now you can provide attr "wx:key" for a "wx:for" to improve performance为警告,不处理不影 ...
- 小程序-Now you can provide attr "wx:key" for a "wx:for" to improve performance
转自:https://www.cnblogs.com/xpwi/p/9878871.html 小程序开发-Now you can provide attr "wx:key" for ...
- 微信小程序——Now you can provide attr "wx:key" for a "wx:for" to improve performance.
在官方的swiper(滑块视图容器)中demo代码,运行时会出现Now you can provide attr "wx:key" for a "wx:for" ...
- 微信小程序警告:Now you can provide attr "wx:key" for a "wx:for" to improve performance.
那是因为在<block wx:for-items="{{imgUrls}}">中不存在wx:key="imgUrls"所以才导致报了个警告. 写成& ...
- 小程序:最难点For的wx:key
转自:http://www.wxappclub.com/topic/536 A:数据改变,导致重新渲染的两种情况: 1:有wx:key的情况(不重新创建,仅改变顺序) 添加元素或改变元素顺序导致数据改 ...
- 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 n ...
- 微信小程序wx:key以及wx:key=" *this"详解:
今天写微信小程序无意中看到控制台给出了这样一行提示: 求解百度才知道,给大家分享一下: 1.wx:for定义 官方文档:在组件上使用 wx:for 控制属性绑定一个数组,即可使用数组中各项的数据重复渲 ...
随机推荐
- django Models cross file ---- 跨app引用文件
一.django 的跨app引用文件是通过import 来实现的,但是import 的路径查找和标准的import 不太一样,django里面更加方便了 二.例子 1.project 结构说明 [ji ...
- Codeforces Round #256 (Div. 2) C. Painting Fence (搜索 or DP)
[题目链接]:click here~~ [题目大意]:题意:你面前有宽度为1,高度给定的连续木板,每次能够刷一横排或一竖列,问你至少须要刷几次. Sample Input Input 5 2 2 1 ...
- mysql 开启慢查询 如何打开mysql的慢查询日志记录
mysql慢查询日志对于跟踪有问题的查询非常有用,可以分析出当前程序里有很耗费资源的sql语句,那如何打开mysql的慢查询日志记录呢,接下来将详细为您介绍 原文出自:http://www.jbxue ...
- atitit.自动生成数据库结构脚本,或者更换数据库,基于hibernate4
atitit.自动生成数据库结构脚本,或者更换数据库,基于hibernate4 目前近况:: 更换数据库,但是是使用spring集成的. <!-- hibernate配置文件路径 --> ...
- CYQ学习主要摘要
这个个人搞的框架不知道到底怎么样,做个项目测试下看看,本来想用EF的,大多数人说性能低,所以先放弃,试试这个,一些主要地方我做个摘录 5:多表怎么搞定? A:视图方式,将多表查询放到数据库里成视图,情 ...
- mysql操作及自动化运维
备份恢复工具:percona-xtrabackup-2.0.0-417.rhel6.x86_64.rpm mysql主从配置命令: 主: 1.编辑主MYSQL 服务器的MySQL配置文件my.cnf, ...
- iOS_5_汤姆猫
终于效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill ...
- css语法和JS语法的对比
CSS语法(不区分大小写) JavaScript语法(区分大小写) border border border-bottom borderBottom border-bottom-color bor ...
- 【C/C++语言】int 在计算机内部的存储
int在32位计算机中占4个字节,主要是想弄清楚这4个字节的在内存中存放的顺序. #include <iostream> using namespace std; typedef stru ...
- Recusively change the owner of files (chown) on Mac OS X
I've just changed my OS X / Mac main user - I've created a new 'coder' user account that I want to u ...