Skip to content

Card Component ​

The card component is generally used in scenarios with multiple list entries that share a unified style.

📌 Platform Compatibility ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage ​

html
<template>
    <hy-card title="标题"></hy-card>
</template>

Card with Thumbnail and Subtitle ​

html
<template>
    <hy-card
        title="刘德华"
        sub-title="简介描述文字"
        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="自定义阴影" box-shadow="0 0 10rpx 10rpx rgba(0, 0, 0, 0.5)"></hy-card>
</template>

Using Custom Slots ​

html
<template>
    <hy-card
        title="素胚勾勒出青花,笔锋浓转淡"
        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">
                    瓶身描绘的牡丹一如你初妆,冉冉檀香透过窗心事我了然,宣纸上走笔至此搁一半
                </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评论"></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="只显示头部" :showFoot="false"></hy-card>

        <hy-card title="只显示主体" :showHead="false" :showFoot="false">
            <template #body>
                <view>这是卡片主体内容</view>
            </template>
        </hy-card>
    </view>
</template>

Custom Padding ​

html
<template>
    <hy-card title="自定义内边距" :paddingHead="20" :paddingBody="30" :paddingFoot="10"></hy-card>
</template>

API ​

Card Props ​

PropDescriptionTypeDefault
fullWhether to leave a gap between the card and the screen edgesbooleanfalse
titleTitle on the left side of the headerstring-
title-colorTitle colorstring-
title-sizeTitle font size; numbers default to pxstring|number-
sub-titleSubtitlestring-
sub-title-sizeSubtitle font size; numbers default to pxstring|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 as well as elements above and below; must include units, e.g. "30rpx 20rpx"string0 0 20rpx
border-radiusBorder radius of the entire card; numbers default to pxstring|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 to the left of the title. Relative paths are not recommended (supports icons from the component library)string-
thumb-widthThumbnail width; height equals width; numbers default to pxstring|number30px
thumb-circleWhether the thumbnail is circularbooleanfalse
rightTextContent on the right sidestring-
right-text-colorRight-side content colorstring-
right-text-sizeRight-side content font size; numbers default to pxstring|number-
paddingPadding for the head, body, and foot sections; see description above; unit rpxstring|number10px
paddingHeadHeader padding; numbers default to pxstring|number-
paddingBodyBody padding; numbers default to pxstring|number-
paddingFootFooter padding; numbers default to pxstring|number-
show-headWhether to show the header (required when displaying the header)booleanfalse
show-footWhether to show the footerbooleantrue
box-shadowOuter shadow of the card, in string formstring|booleantrue
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events ​

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

Slots ​

SlotDescriptionValue Received
headerCustom card header content-
bodyCustom card body content-
footerCustom card footer content-

CSS Variables ​

VariableDescriptionDefault
--hy-card-font-sizeBody font sizeFollows --hy-font-size-base (28rpx)
--hy-card-title-max-widthMaximum title width400rpx
--hy-card-head-paddingHeader padding20rpx 20rpx 10rpx
--hy-card-body-paddingBody content padding10rpx 20rpx 10rpx
--hy-card-foot-paddingFooter padding10rpx 20rpx 20rpx
--hy-card-title-font-sizeHeader title font sizeFollows --hy-font-size-base (28rpx)
--hy-card-sub-colorHeader subtitle colorFollows --hy-text-color--grey
--hy-card-sub-font-sizeHeader subtitle font sizeFollows --hy-font-size-sm (24rpx)
--hy-card-right-colorHeader right-side text colorFollows --hy-text-color--grey
12:33
battery