踩坑記錄2-----小程式遍歷陣列渲染資料, 列印當前點選為undefined
阿新 • • 發佈:2020-09-08
正確 <view class="orderOne" v-for="(item,index) in allOrderList" :key="index"> <view class="orderTop" @tap="toOrgPage(item,index)"> <image src="../../static/btn_campus.png" mode=""></image> <view class="orderNum">{{item.order.orgName ? item.order.orgName : ''}}{{item.order.campName ? '(' + item.order.campName + ')' : ''}}</view> <image class="topErrow" src="../../static/back_white@[email protected]" mode=""></image> <view class="orderStatus">{{item.order.orderStatus}}</view> </view> <view class="orderLine"></view> <view class="course" v-for="(item2,index) in item.order.orderItemsList" :key="index" @tap="toOrderDetail(item2)"> <view class="img"> <image :src="item2.itemLogo" mode="aspectFill"></image> </view> <view class="courseInfo"> <view class="courseName">{{item2.itemName}}</view> <view class="subHeading">{{item2.subheading}}</view> <view class="priceName">{{item2.priceName}} {{item2.classTimeCount + '課時'}}</view> <view class="priceNum"> <view class="price"> <text class="priceSymbol">¥</text> {{item2.price}} </view> <view class="courseNum">x{{item2.itemNumber}}</view> </view> </view> </view>
之前, 遍歷時
v-for="(item,index) in allOrderList" 沒有加 index, 唯一值用的是 :key='item.id', 列印大當前點選為 undefined, 加上index打印出來了!!!!