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

child子组件代码

  1. <template>
  2. <view>
  3. <view>{{ctitle}}</view>
  4. </view>
  5. </template>
  6. <script>
  7. import wepy from 'wepy'
  8. export default class Child extends wepy.component{
  9. props = {
  10. ctitle:{
  11. type:String,
  12. default: 'null'
  13. }
  14. }
  15. }
  16. </script>

父组件代码:

  1. <template>
  2. <view>
  3. <repeat for="{{titleList}}" key="index" index="index" item="item">
  4. <child :ctitle="item"></child>
  5. </repeat>
  6. </view>
  7. </template>
  8. <script>
  9. import wepy from 'wepy'
  10. import Child from '@/components/child'
  11. export default class Demo3 extends wepy.page{
  12. data = {
  13. titleList:["网页设计与开发","Vue企业开发实战","微信小程序开发实战"]
  14. }
  15. components = {
  16. child:Child
  17. }
  18. }
  19. </script>

image.png