请 老师给个思路,以下布局CSS部分实现不了,谢谢

来源:1-5 项目作业

叫我丽红

2022-06-28 16:32:34

https://img.mukewang.com/climg/62babca0096355c704920539.jpg

写回答

1回答

好帮手慕久久

2022-06-28

同学你好,可以参考如下demo:

<template>
  <div class="wrapper">
    <div class="title">我的全部购物车(2)</div>
    <div class="shops">
      <div
        class="empty"
        v-if="Object.keys(cartListWithProducts).length === 0"
      >购物车当前为空</div>
      <div
        class="shop"
        v-for="(item, index) in cartListWithProducts"
        :key="index"
      >
        <div class="shop__title">
          {{item.shopName}}
        </div>
        <div class="products">
          <div class="products__list">
            <template
              v-for="(product, product_Idx ) in item.productList"
              :key="product._id"
            >
              <div
                v-if="product.count > 0 && product_Idx <= 1"
                class="products__item"
              >
                <img class="products__item__img" :src="product.imgUrl" />
                <div class="products__item__detail">
                  <h4 class="products__item__title">{{product.name}}</h4>
                  <p class="products__item__price">
                    <span>
                      <span class="products__item__yen">&yen; </span>
                      {{product.price}} x {{product.count}}
                    </span>
                    <span class="products__item__total">
                      <span class="products__item__yen">&yen; </span>
                     99.9
                    </span>
                  </p>
                </div>
              </div>
            </template>
             <div class="total" v-if="item.productList.length>=3">共计{{item.productList.length}}件/1.4kg <div class="total__arrow iconfont">&#xe6f2;</div> </div>
          </div>
        </div>
       
      </div>
    </div>
  </div>
  <Docker :currentIndex="1"/>
</template>

<script>
import Docker from '../../components/Docker'

export default {
  name: 'CartList',
  components: { Docker },
  setup() {
    // 购物车的数据,使用假的就行--》可以自己写一个数据
    const cartListWithProducts = [
      {
        "shopName" :"沃尔玛",
        "productList" : [
          {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/tomato.png",
            "name":"番茄250g/份",
            "count":"3",
            "price": "33.6 "
          },
          {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/cherry.png",
            "name":"提子250g/份",
            "count":"3",
            "price": "33.6 "
          },
           {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/cherry.png",
            "name":"提子250g/份",
            "count":"3",
            "price": "33.6 "
          }
        ]
      },
      {
        "shopName" :"京东7FRESH七鲜",
        "productList" : [
          {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/orange.png",
            "name":"橙子 250g/份",
            "count":"3",
            "price": "33.6 "
          },
          {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/cherry.png",
            "name":"提子250g/份",
            "count":"3",
            "price": "33.6 "
          }
        ]
      },
      {
        "shopName" :"百果园",
        "productList" : [
          {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/tomato.png",
            "name":"番茄250g/份",
            "count":"3",
            "price": "33.6 "
          },
          {
            "imgUrl": "http://www.dell-lee.com/imgs/vue3/cherry.png",
            "name":"提子250g/份",
            "count":"3",
            "price": "33.6 "
          }
        ]
      }
    ]
    return { cartListWithProducts }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  position: absolute;
  left: 0;
  top: 0;
  bottom: .5rem;
  right: 0;
  background:#F8F8F8;
}
.title {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
  line-height: .44rem;
  background: #fff;
  font-size: .16rem;
  color: #333;
  text-align: center;
}
.empty {
  line-height: .44rem;
  color: #999;
  font-size: .16rem;
  text-align: center;
}
.shops {
  overflow-y: scroll;
  position: absolute;
  top: .6rem;
  right: .18rem;
  bottom: .1rem;
  left: .18rem;
}
.shop {
  margin-bottom: 0.16rem;
  background:#fff;
  border-radius: .1rem;
  overflow: hidden;
  &__title {
    padding: .16rem;
    font-size: .16rem;
    color: #333;
  }
  &__wrapper {
    overflow-y: scroll;
    margin: 0 .18rem;
    position: absolute;
    left: 0;
    right: 0;
    bottom: .6rem;
    top: 2.6rem;
  }
}
.products {
  &__list {
    background: #fff;
  }
  .total {
    display: flex;
    justify-content: center;
    width: 82%;
    padding: 0.1rem;
    font-size: .14rem;
    color: #999999;
    margin:0 auto 0.16rem;
    text-align:center;
    background: #F5F5F5;
    &__arrow {
      width: .2rem;
      margin-left: .06rem;
      transform: rotate(-90deg);
      font-weight: bold;
      color: #C2C4CA;
    }
  }
  &__item {
    position: relative;
    display: flex;
    padding: 0 .16rem 0.16rem .16rem;
    &__img {
      width: .46rem;
      height: .46rem;
      margin-right: .16rem;
    }
    &__detail {
      flex: 1;
    }
    &__title {
      margin: 0;
      line-height: .2rem;
      font-size: .14rem;
      color:#333;
     overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
    }
    &__price {
      display: flex;
      margin: .06rem 0 0 0;
      line-height: .2rem;
      font-size: .14rem;
      color: #E93B3B;
    }
    &__total {
      flex: 1;
      text-align: right;
      color:#000;
    }
    &__yen {
      font-size: .12rem;
    }
  }
}
</style>

其中Docker组件,用的源码中的,可以下载源码获取。

祝学习愉快!


0

0 学习 · 15276 问题

查看课程