小程序

wepy1.X 组件循环的坑点

2019-11-29  本文已影响0人  大咔丶

当需要循环渲染WePY组件时(类似于通过wx:for循环渲染原生的wxml标签),必须使用WePY定义的辅助标签<repeat>,代码如下:

<template>
    <!-- 注意,使用for属性,而不是使用wx:for属性 -->
    <repeat for="{{list}}" key="index" index="index" item="item">
        <!-- 插入<script>脚本部分所声明的child组件,同时传入item -->
        <child :item="item"></child>
    </repeat>
</template>

自定义组件嵌套不用repeat props传不进去的,所以还是得用repeat,在repeat的子组件中避免使用computed, data这些带bug的东西,不用repeat想都别想...

果然是坑点,如果用原生wx:for循环,子组件就无法获得props!! 传送

上一篇 下一篇

猜你喜欢

热点阅读