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>
显示效果如下: