Skip to content

Card Component

The card component is generally used for scenarios with multiple list entries and a unified style.

📌 Platform Compatibility

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯 Basic Usage Example

html
<template>
    <hy-card title="Title"></hy-card>
</template>

Card with Thumbnail and Subtitle

html
<template>
    <hy-card
        title="Andy Lau"
        sub-title="Brief description text"
        right-text="2020-05-15"
        thumb="https://example.com/avatar.jpg"
        thumb-width="40"
        thumbCircle
        full
    ></hy-card>
</template>

Custom Shadow

html
<template>
    <hy-card title="Custom Shadow" box-shadow="0 0 10rpx 10rpx rgba(0, 0, 0, 0.5)"></hy-card>
</template>

Using Custom Slots

html
<template>
    <hy-card
        title="Blue flowers sketched on plain porcelain, the brushstroke shifting from rich to light"
        sub-title="2020-05-15"
        thumb="http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg"
        full
    >
        <template #body>
            <view class="u-body-item">
                <view class="u-body-item-title">
                    Peonies painted on the vase like your first makeup, lingering sandalwood drifting through the window reveals my thoughts, the brush on the rice paper pauses halfway here
                </view>
                <image
                    src="https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg"
                    mode="aspectFill"
                ></image>
            </view>
        </template>
        <template #footer>
            <hy-icon name="chat-fill" size="25" label="30 comments"></hy-icon>
        </template>
    </hy-card>
</template>

<style scoped lang="scss">
    .u-body-item {
        font-size: 32rpx;
        padding: 20rpx 10rpx;
        display: flex;
        justify-content: space-between;
    }

    .u-body-item image {
        width: 120rpx;
        height: 120rpx;
        border-radius: 8rpx;
        margin-left: 12rpx;
    }
</style>
html
<template>
    <view>
        <hy-card title="Show header only" :showFoot="false"></hy-card>

        <hy-card title="Show body only" :showHead="false" :showFoot="false">
            <template #body>
                <view>This is the card body content</view>
            </template>
        </hy-card>
    </view>
</template>

Custom Padding

html
<template>
    <hy-card title="Custom Padding" :paddingHead="20" :paddingBody="30" :paddingFoot="10"></hy-card>
</template>

API

Card Props

ParameterDescriptionTypeDefault
fullWhether to leave gaps between the card and both sides of the screenbooleanfalse
titleTitle on the left of the headerstring-
title-colorTitle colorstring-
title-sizeTitle font size, default unit px for numeric valuesstring|number-
sub-titleSubtitlestring-
sub-title-sizeSubtitle font size, default unit px for numeric valuesstring|number-
sub-title-colorSubtitle font colorstring-
borderWhether to show the borderbooleanfalse
indexUsed to identify which card was clickedstring|number-
marginSpacing between the card and the screen edges and elements above/below, must include units, e.g. "30rpx 20rpx"string0 0 20rpx
border-radiusBorder radius of the entire card, default unit px for numeric valuesstring|number8px
head-styleCustom header style, in object formCSSProperties-
body-styleCustom body style, in object formCSSProperties-
foot-styleCustom footer style, in object formCSSProperties-
head-border-bottomWhether to show the header's bottom borderbooleanfalse
foot-border-topWhether to show the footer's top borderbooleanfalse
thumbThumbnail path; if set, it will be displayed on the left of the title. Relative paths are not recommended (supports component library icons)string-
thumb-widthThumbnail width, height equals width, default unit px for numeric valuesstring|number30px
thumb-circleWhether the thumbnail is circularbooleanfalse
rightTextRight-side contentstring-
right-text-colorRight-side content colorstring-
right-text-sizeRight-side content font size, default unit px for numeric valuesstring|number-
paddingPadding for the head, body, and foot sections, see description above, unit rpxstring|number10px
paddingHeadHeader padding, default unit px for numeric valuesstring|number-
paddingBodyBody padding, default unit px for numeric valuesstring|number-
paddingFootFooter padding, default unit px for numeric valuesstring|number-
show-headWhether to show the header (required when displaying the header)booleanfalse
show-footWhether to show the footerbooleantrue
box-shadowCard outer shadow, in string formstring|booleantrue
customStyleCustom external styles to be usedCSSProperties-
customClassCustom external class namestring-

Events

Event NameDescriptionCallback Parameters
clickTriggered when any part of the entire card is clickedindex: identifier passed by the user
head-clickTriggered when the card header is clickedindex: identifier passed by the user
body-clickTriggered when the card body is clickedindex: identifier passed by the user
foot-clickTriggered when the card footer is clickedindex: identifier passed by the user

Slots

Slot NameDescriptionAccepted Values
headerCustom card header content-
bodyCustom card body content-
footerCustom card footer content-
03:29