本技术博客介绍了如何使用 Ant Design Vue 构建一个响应式卡片布局。该布局可用于展示图片、数据或其他内容,适用于各种应用场景,例如相册、博客或电子商务网站。
本代码实现了以下基本功能:
<template>
<div class="bg-gray-100 h-screen">
<!-- ... -->
</div>
</template>
<script lang="tsx" setup>
import { ref } from "vue";
import * as echarts from "echarts";
import { h } from "vue";
import { createComponent } from "echarts-for-vue";
import { default as MessageOutlined } from "@ant-design/icons-vue/es/icons/MessageOutlined";
import { Calendar } from "v-calendar";
import { BMap } from "vue3-baidu-map-gl";
const ECharts = createComponent({ echarts, h });
</script>
<div class="grid grid-cols-3 gap-4">
<a-card
class="hover:shadow-lg cursor-pointer"
hoverable
style="width: 100%; height: 100%;"
>
<img
src="https://source.unsplash.com/random/300x300"
alt="A photo of a woman"
/>
</a-card>
<!-- ... -->
</div>
a-card
组件创建卡片。hoverable
属性允许卡片在悬停时显示阴影效果。cursor-pointer
属性使卡片可点击。.a-card {
background-color: #fff;
border-radius: 0.25rem;
box-shadow: rgba(0, 0, 0, 0.05) 0 1px 2px 0;
transition: box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1),
opacity 15ms linear 30ms, transform 270ms cubic-bezier(0, 0, 0.2, 1) 0ms;
}
.hover\:shadow-lg {
@media (hover: hover) {
box-shadow: rgba(0, 0, 0, 0.1) 0 4px 12px;
}
}
.cursor-pointer {
cursor: pointer;
}