当需要循环渲染WePY组件时(类似于通过wx:for循环渲染原生的wxml标签)
必须使用WePY定义的辅助标签<repeat>
,代码如示例6-3所示
child子组件代码
<template>
<view>
<view>{{ctitle}}</view>
</view>
</template>
<script>
import wepy from 'wepy'
export default class Child extends wepy.component{
props = {
ctitle:{
type:String,
default: 'null'
}
}
}
</script>
父组件代码:
<template>
<view>
<repeat for="{{titleList}}" key="index" index="index" item="item">
<child :ctitle="item"></child>
</repeat>
</view>
</template>
<script>
import wepy from 'wepy'
import Child from '@/components/child'
export default class Demo3 extends wepy.page{
data = {
titleList:["网页设计与开发","Vue企业开发实战","微信小程序开发实战"]
}
components = {
child:Child
}
}
</script>