1. 程式人生 > >小程式中如何實現遍歷

小程式中如何實現遍歷

1.首先在data中對陣列物件進行定義

tp:[

{

url: './img/3.png',

name: '11支康乃馨',

},{

url: './img/4.png',

name: '19支紅玫瑰',

},{

url: './img/5.png',

name: '20支百合',

},{

url: './img/6.png',

name: '99只紅玫瑰'

}

],

2.然後在使用block標籤

<view style="background:pink;border-left:1px solid white;">

<block wx:for="{{tp}}" wx:key="*this">

<view style="border-bottom:1px solid white">

<image src="{{item.url}}"></image>

<text style="color:white">{{item.name}}</text>

</view>

3.即可得到遍歷的圖片與名字