Skip to content

Card 卡片

将信息聚合在卡片容器中展示。

基础用法

使用slot传入卡片的内容,包括header,content,footer三个部分。content使用默认插槽传递,header使用header插槽,footer使用footer插槽。

这是卡片的header

卡片内容

卡片内容

卡片内容

卡片内容


<template>
    <ym-card>
        <template #header>
           <strong>这是卡片的header</strong>
        </template>
        <template #footer>
           <strong>这是卡片的footer</strong>
        </template>
        <p v-for="item in 4" :key="item">卡片内容</p>
    </ym-card>
</template>

使用props传递内容

使用header,footer,content三个props来传递内容。(可以与上面的slot方式混合使用,组件优先渲染props内容)

卡片header
卡片内容


<template>
    <ym-card header="卡片header" footer="卡片footer" content="卡片内容"> </ym-card>
</template>

卡片阴影

使用shadow属性可以给卡片添加阴影。可以控制阴影的出发时机。

shadow: always
这是一个卡片组件容器
shadow: hover
这是一个卡片组件容器
shadow: never
这是一个卡片组件容器


<template>
    <div class="container">
        <ym-card shadow="always">
            <template #header>
                <strong>shadow: always</strong>
            </template>
            这是一个卡片组件容器
        </ym-card>
        <ym-card shadow="hover">
            <template #header>
                <strong>shadow: hover</strong>
            </template>
            这是一个卡片组件容器
        </ym-card>
        <ym-card shadow="never">
            <template #header>
                <strong>shadow: never</strong>
            </template>
            这是一个卡片组件容器
        </ym-card>
    </div>
</template>
<style scoped>
.container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 10px;
}
</style>

Card API

Props

NameDescriptionTypeDefault
header卡片头部内容,可以使用slot传入string-
content卡片主体内容,可以使用slot传入string-
footer卡片底部内容,可以使用slot传入string-
shadow阴影触发方式alwayshover
contentClass主题内容类名string-
contentStyle主体内容样式CSSProperties-

Slots

NameDescription
default默认插槽
header头部插槽
footer底部插槽