Text 组件
文本组件,用于显示文本内容,支持多种语义化变体,是 A2UI 协议的核心基础组件。
基础用法
Props API
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | string | - | 组件唯一标识(必填) |
component | string | Text | 组件类型(必填) |
text | string | StringValue | null | null | 文本内容,支持直接字符串或对象格式 |
variant | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'caption' | 'body' | 'body' | 语义化变体,决定渲染的 HTML 标签 |
fontWeight | string | number | - | 字体粗细,如 'bold'、700 等 |
StringValue 类型
当 text 使用对象格式时,支持以下属性:
| 属性名 | 类型 | 说明 |
|---|---|---|
literalString | string | 直接字符串值 |
path | string | 数据模型路径引用 |
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"
}
]