问题描述
通过uniapp编译成钉钉小程序之后,在支付宝ide里面切换到钉钉小程序预览,会报错af-appx.worker.min.js:26 Cannot read properties of null (reading 'index')
Please check your component:
in /node-modules/uview-ui/components/u-loading-icon/u-loading-icon
排查
发现这个组件里面用了Array.from({ length: 12 })来渲染数组,view上绑定了a:key="index"的写法,看了钉钉小程序开发文档介绍https://open.dingtalk.com/document/orgapp/list-rendering#title-ips-etx-0yr
我理解是a:index="index"代表的是列表项的属性index,而非索引;Array.from({ length: 12 })的列表项为undefined,故而undefined.index会报错,而支付宝小程序和微信小程序是一样的写法但是没有这个报错,猜测对此做了兼容?
代码片段
data: {
array12: Array.from({ length: 12 }),
}
代码片段
<view
a:for="{{array12}}"
a:for-index="index"
a:for-item="item"
class="{{((('u-loading-icon__dot')+' '+'data-v-8ae91632')+' '+virtualHostClass)}}"
style="{{virtualHostStyle}}"
a:key="index"
>
</view>