8爆款推荐样式布局

home组件文件夹Recommend.vue

<template>
  <div class="recommend">
    <Card />
    <ul>
      <li v-for="(item, index) in RecommendList" :key="index">
        <h2>
          <img :src="item.imgUrl" alt="" />
        </h2>
        <div>
          <h3>{{ item.name }}</h3>
          <p>{{ item.content }}</p>
          <div class="price">
            <span>$</span>
            <b>{{ item.price }}</b>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import Card from "@/components/home/Card";
export default {
  components: {
    Card,
  },
  data() {
    return {
      RecommendList: [
        {
          id: 1,
          name: "龙井1铁250G",
          content: "鲜爽甘醇,口粮首选",
          price: 68,
          imgUrl: "./images/h1.jpeg",
        },
        {
          id: 2,
          name: "龙井1铁250G",
          content: "鲜爽甘醇,口粮首选",
          price: 68,
          imgUrl: "./images/h2.jpeg",
        },
        {
          id: 3,
          name: "龙井1铁250G",
          content: "鲜爽甘醇,口粮首选",
          price: 68,
          imgUrl: "./images/h3.jpeg",
        },
        {
          id: 4,
          name: "龙井1铁250G",
          content: "鲜爽甘醇,口粮首选",
          price: 68,
          imgUrl: "./images/h4.jpeg",
        },
      ],
    };
  },
};
</script>

<style scoped>
.recommend ul li {
  position: relative;
}
.recommend ul li h2 {
  text-align: center;
}
.recommend ul li img {
  width: 9.6rem;
  height: 3.84rem;
  border-radius: 0.32rem;
}
.recommend ul li > div {
  position: absolute;
  top: 0;
  right: 0;
}
.recommend ul li > div {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  padding: 0.5333rem;
}
.recommend ul li > div h3 {
  font-size: 0.32rem;
  margin-bottom: 10px;
}
.recommend ul li > div p {
  font-size: 0.42666rem;
}
.price {
  color: red;
  text-align: right;
  margin-top: 0.5333rem;
}
</style>

新建card组件

使用插槽

代码如下

<template>
  <div class="">
    <div class="title">
      <slot>
        <span>火爆推荐</span>
      </slot>
    </div>
  </div>
</template>

<script>
export default {};
</script>

<style scoped>
.title {
  text-align: center;
  font-size: 0.5rem;
  color: #333333;
}
.title span {
  position: relative;
}
.title span::before {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
  background: #d4c0a7;
  top: 50%;
  margin-top: -4px;
  left: -0.5rem;
}

.title span::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
  background: #d4c0a7;
  top: 50%;
  margin-top: -4px;
  right: -0.5rem;
}
</style>

显示效果如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值