商品卡片组件

展示

在这里插入图片描述

代码

<template>
  <div class="goodCard flex-column" :style="{width: width, height: height}" @mouseover="show=true" @mouseleave="show=false">
    <div class="goodCard-img" :style="{width: width, height: width}">
      <img style="object-fit: contain;" :src="info.goodImg" :alt="info.goodImg">
      <div class="tips" :class="show ? 'hidden':'show'" @click="onSearchLike">
        <span>找相似</span>
      </div>
    </div>
    <div class="title">{{ info.goodName }}</div>
    <div class="bottom">
      <div class="price">
        <span class="symbol"></span>{{ info.price }}
      </div>
      <div class="bought">
        {{ info.bought }}人付款
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

let show = ref(false)

function onSearchLike() {
  emit('searchLike')
}

const emit = defineEmits<{
  (e: 'searchLike')
}>()

const props = defineProps({
  width: {
    type: String,
    default: ''
  },
  height: {
    type: String,
    default: ''
  },
  info: {
    type: Object,
    default: () => {}
  }
})
</script>

<style lang="scss" scoped>
.goodCard {
  padding: 7px;
  border-radius: 12px;
  cursor: pointer;
  &:hover {
    box-shadow: 0 19px 39px 0 rgba(0,0,0,.2);
  }
  &-img {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    @include bg_color('bg-color');
  }
  .title {
    margin: 10px 5px 5px;
    font-size: 16px;
    line-height: 22px;
    height: 44px;
    overflow: hidden;
    word-wrap: break-word;
  }
  .price {
    color: #ff5000;
    font-size: 22px;
    .symbol {
      font-size: 16px;
      font-family: Microsoft Yahei;
    }
  }
  .bottom {
    height: 33px;
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #999;
    .bought {
      margin-left: 10px;
    }
  }
}

.tips  {
  position: absolute;
  height: 29px;
  width: 100%;
  left: 0;
  bottom: 0;
  background-color: #ff2000;
  text-align: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  line-height: 29px;
  margin-top: -14px;
}

.hidden {
  opacity: 1;
  transition: opacity 1s;
}

.show {
  opacity: 0;
  transition: opacity 1s;
}
</style>
属性
属性名描述
width卡片宽度
height卡牌高度
info卡片信息

ps: 卡片信息为对象,包括以下一些属性

info: {
	// 商品名称
	goodName: '',
	// 商品照片
	goodImg: '',
	// 商品价格
	price: '',
	// 商品出售数量
	bought: '',
}
方法
方法名描述
searchLike“ 找相似 ” 的点击事件
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值