V1.0.0
Skip to content

Text 组件

文本组件,用于显示文本内容,支持多种语义化变体,是 A2UI 协议的核心基础组件。

基础用法

Props API

属性名类型默认值说明
idstring-组件唯一标识(必填)
componentstringText组件类型(必填)
textstring | StringValue | nullnull文本内容,支持直接字符串或对象格式
variant'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'caption' | 'body''body'语义化变体,决定渲染的 HTML 标签
fontWeightstring | number-字体粗细,如 'bold'700

StringValue 类型

text 使用对象格式时,支持以下属性:

属性名类型说明
literalStringstring直接字符串值
pathstring数据模型路径引用

path 支持说明

通用绑定格式见 path 数据绑定速查

属性支持 path说明
text文本内容(dataModel 路径或 @row.xxx 作用域)
variant / fontWeight静态配置

dataModel 路径:

json
{ "text": { "path": "/data/title" }, "variant": "h2" }

列表/表格模板作用域:

json
{ "text": { "path": "@row.label" }, "variant": "body" }

variant 可选值

渲染标签说明
h1<h1>一级标题
h2<h2>二级标题
h3<h3>三级标题
h4<h4>四级标题
h5<h5>五级标题
caption<small>说明文字/小字
body<span>正文(默认)

使用示例

基础用法

直接传入字符串:

json
{
  "id": "text_001",
  "component": "Text",
  "text": "Hello World",
  "variant": "body"
}

StringValue 对象格式

使用 literalString

json
{
  "id": "text_literal",
  "component": "Text",
  "text": {
    "literalString": "固定文本内容"
  },
  "variant": "h2"
}

使用 path 引用数据模型:

json
{
  "id": "text_path",
  "component": "Text",
  "text": {
    "path": "/data/title"
  },
  "variant": "h1"
}

自定义字体粗细

json
{
  "id": "text_bold",
  "component": "Text",
  "text": "加粗文本",
  "variant": "body",
  "fontWeight": 700
}

说明文字

json
{
  "id": "caption_text",
  "component": "Text",
  "text": "这是一段说明文字",
  "variant": "caption"
}

与 WinDesign 组件配合

Text 组件常作为 WinDesign 组件的内容:

json
[
  {
    "id": "button_submit",
    "component": "WButton",
    "type": "primary",
    "child": "button_text"
  },
  {
    "id": "button_text",
    "component": "Text",
    "text": "提交",
    "variant": "body"
  }
]