openharmony 鸿蒙 js-apis-data-UdmfComponents

2026-08-25 浏览 (1)

@ohos.data.UdmfComponents (Content Card)

A content card designed in the ContentForm struct. You can set the title (mandatory), description, application icon, application name, redirection link, and content image for the content card. When a user taps the card, a callback of the pass event is triggered to redirect the user to the specified page if the target link is set.

NOTE

This component is supported since API version 20. Updates will be marked with a superscript to indicate their earliest API version.

Module to Import

import { ContentFormCard, FormType } from '@kit.ArkData';

Child Component

N/A

ContentFormCard

ContentFormCard({contentFormData: uniformDataStruct.ContentForm, formType: FormType, formWidth?: number, formHeight?: number, handleOnClick?: Function})

Defines the information of a content card component that displayed in an application, including the title, description, content image, application information, and the like.

Decorator: @Component

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeMandatoryDecoratorDescription
contentFormDatauniformDataStruct.ContentFormYes-Content card data.
formTypeFormTypeYes@PropContent card type, which affects the size of the content card.
formWidthnumberNo@PropCard width. The value ranges from 0.8 to 1.2 times the default width of the content card type. If formType is set to TYPE_SMALL, the value ranges from 0.4 to 1.2 times the default width of the content card type. The unit is vp.
formHeightnumberNo@PropCard height. If title in contentFormData is an empty string, the card height is the passed value. Otherwise, the value ranges from 0.8 to 1.2 times the default width of the content card type. If formType is set to TYPE_SMALL, the value ranges from 0.4 to 1.2 times the default width of the content card type. The unit is vp.
handleOnClickFunctionNo-Callback for the click event.

FormType

Enumerates content card types, including large, medium, and small.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameValueDescription
TYPE_BIG04 × 4. The default card width and height are both 200.
TYPE_MID14 × 2. The default card width and height are 200 and 100, respectively.
TYPE_SMALL22 × 1. The default card width and height are 137 and 83, respectively.

Example

import { uniformDataStruct } from '@kit.ArkData'

@Entry
@Component
struct Index {
  @State contentForm: uniformDataStruct.ContentForm = {
    uniformDataType: 'general.content-form',
    title: ''
  };
  @State startToShow: boolean = false;

  aboutToAppear(): void {
    this.initData();
  }

  async initData() {
    let context = this.getUIContext().getHostContext();
    if (!context) {
      return;
    }
    try {
      let appIcon = await context.resourceManager.getMediaContent($r('app.media.startIcon').id);
      let thumbImage = await context.resourceManager.getMediaContent($r('app.media.foreground').id);
      this.contentForm = {
        uniformDataType: 'general.content-form',
        title: "Content form title",
        thumbData: appIcon,
        description: "Content form description",
        appIcon: thumbImage,
        appName: "com.test.demo"
      };
    } catch (err) {
      console.error("Init data error");
    }
  }

  build() {
    Column() {
      Button('show card')
        .onClick(() => {
          this.startToShow = true;
        })
      if (this.startToShow) {
        ContentFormCard({
          contentFormData: this.contentForm,
          formType: FormType.TYPE_SMALL,
          formWidth: 110,
          formHeight: 50,
          handleOnClick: () => {
            console.info("Clicked card");
          }
        })
      }
    }
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-distributedKVStore-sys

openharmony 鸿蒙 capi-oh-preferences-h

openharmony 鸿蒙 capi-udmf-oh-udshyperlink

openharmony 鸿蒙 js-apis-data-dataSharePredicates

openharmony 鸿蒙 capi-udmf-oh-udsappitem

openharmony 鸿蒙 capi-rdb-oh-data-vbuckets

openharmony 鸿蒙 capi-rdb-oh-predicates

openharmony 鸿蒙 capi-rdb-oh-data-value

openharmony 鸿蒙 capi-preferences-oh-preferencespair

openharmony 鸿蒙 errorcode-datashare

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/IuaQEpXZ