卡片组件是一种常见的UI元素,广泛应用于电子商务、社交媒体和信息展示等场景。它可以用来展示产品信息、用户信息、新闻摘要或其他各种内容。
本文介绍的卡片组件基于 Ant Design Vue 框架开发,它提供了以下基本功能:
npm install ant-design-vue
import { ACard, ATag, ARate, AButton } from 'ant-design-vue'
<template>
<a-card>
<div class="flex items-center justify-between">
<h2 class="text-xl font-bold">{{ title }}</h2>
<a-tag color="green" class="ml-2">{{ discount }}</a-tag>
</div>
<div class="flex items-center justify-between mt-4">
<img :src="image" alt="product" class="w-20 h-20 object-cover rounded-md" />
<div class="ml-4">
<h3 class="text-lg font-bold">{{ name }}</h3>
<div class="flex items-center mt-2">
<a-rate :allow-half="true" :value="rate" disabled />
<span class="ml-2 text-sm text-gray-500">({{ reviews }} reviews)</span>
</div>
<div class="flex items-center mt-2">
<span class="text-lg font-bold">{{ price }}</span>
<span class="text-sm line-through ml-2 text-gray-500">{{ oldPrice }}</span>
</div>
</div>
</div>
<div class="flex items-center justify-end mt-4">
<a-button type="primary" size="small">Shop Now</a-button>
</div>
</a-card>
</template>
<script>
export default {
props: {
title: {
type: String,
required: true
},
discount: {
type: String,
required: false,
default: ''
},
image: {
type: String,
required: true
},
name: {
type: String,
required: true
},
rate: {
type: Number,
required: true
},
reviews: {
type: Number,
required: true
},
price: {
type: String,
required: true
},
oldPrice: {
type: String,
required: false,
default: ''
}
}
}
</script>
<template>
<div>
<a-card
title="Fresh Meat"
discount="40% OFF"
image="https://source.unsplash.com/random/200x200"
name="Beef Brisket"
rate="4.5"
reviews="234"
price="$22.99"
oldPrice="$29.99"
/>
</div>
</template>
开发这段代码的过程让我深入了解了 Ant Design Vue 框架的卡片组件。该组件提供了丰富的功能和可定制性,使其适用于各种应用场景。
未来,该卡片组件可以进一步优化和拓展,例如: