主页(五)-商品列表——多层数据嵌套的遍历 & 引用-封装的通用接口调用方法

商品列表——多层数据嵌套的遍历 & 引用-封装的通用接口调用方法

  • 商品列表布局
<!-- 楼层效果 -->
<div class="floor" >
   <!-- 顶部标签 -->
  <div class="floor-title">
    <img src="" mode="aspectFill">
  </div> 
   <!-- 底部图片 -->
  <div class="floor-content">
    <div class="left">
      <img src="" mode="aspectFill">
    </div>
    <div class="right">
      <img src="img.image_src" mode="aspectFill">
      <img src="img.image_src" mode="aspectFill">
      <img src="img.image_src" mode="aspectFill">
      <img src="img.image_src" mode="aspectFill">
    </div>
  </div>
</div>

楼层结构

在这里插入图片描述

主要样式

.floor .floor-title  {
padding: 10rpx;
background-color: #eee;
}
.floor .floor-title img {
height: 100rpx;
}
.floor .floor-content {
display: flex;
padding: 20rpx;
}
.floor .floor-content .left {
padding-right: 10rpx;
}
.floor .floor-content .left img {
width:232rpx;
height:385rpx;
}
.floor .floor-content .right {
flex: 1;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.floor .floor-content .right img {
width:232rpx;
height:188rpx;
border-radius:4px;
}

参考样式

 .floor{
    .floor-title{
      width:100%;
    }
    .floor-content{
      display: flex;
      justify-content: space-between;
      width:100%;
      .left {
        img {
          width:232rpx;
          height:385rpx;
        }
      }
      .right {
        flex:1;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        img {
          width:232rpx;
          height:188rpx;
          border-radius:4px;
        }
      }
    }
  }

楼层基本布局效果

在这里插入图片描述

  • 对接商品接口数据
async floorData () {
  this.floor = await this.queryData('home/floordata')
}

对接数据

结构

  <!-- 楼层效果 -->
    <div :key='index' class="floor" v-for='(item, index) in floor'>
      <!-- 顶部标签 -->
      <div class="floor-title">
        <img :src="item.floor_title.image_src">
      </div>
      <!-- 底部图片 -->
      <div class="floor-content">
        <div class="left">
          <img :src="item.product_list[0].image_src">
        </div>
        <div class="right">
             <!-- 第一张图片不要 -->
          <img v-if='i>0' :key='i' v-for='(img, i) in item.product_list' :src="img.image_src">
        </div>
      </div>
    </div>

数据

import request from '../../utils/request.js'
export default {
  data () {
    return {
     floor: [],
    }
  },
  methods: {
     async floorData () {
       // 获取楼层数据
       this.floor = await request('home/floordata')
     },
 },
  created () {
      //调用数据
    this.floorData ()
  },
}

打印楼层数据

在这里插入图片描述

详细版

在这里插入图片描述

遍历数据,显示效果

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值