一、引言HarmonyOS NEXT 是华为全栈自研的操作系统ArkTS 是其原生开发语言。ArkUI 提供声明式布局能力Column是其中使用频率最高的组件。本文以Column alignItems(ItemAlign.Start)布局模式为核心通过实战 Demo 讲解Column 的基本原理与属性alignItems交叉轴对齐控制justifyContent主轴分布策略ArkTS 严格模式的常见编译错误与解决方案二、ArkUI 布局体系概述2.1 布局容器三剑客容器主轴方向交叉轴适用场景Column垂直从上到下水平纵向列表、表单、文章详情Row水平从左到右垂直导航栏、按钮组、标签行Stack层叠Z 轴无悬浮按钮、遮罩层、重叠布局2.2 主轴与交叉轴理解 Column 的关键在于分清主轴Main Axis和交叉轴Cross AxisColumn ┌─────────────────────┐ │ 主轴垂直↓ │ │ ┌───────┐ │ │ │ 子组件A │←交叉轴→ │ │ └───────┘ │ │ ┌───────┐ │ │ │ 子组件B │ │ │ └───────┘ │ └─────────────────────┘Column 的两个核心属性分别控制这两个轴Column(){...}.alignItems(HorizontalAlign.Start)// 控制交叉轴水平对齐.justifyContent(FlexAlign.Start)// 控制主轴垂直分布三、Column 容器深度解析3.1 基本用法EntryComponentstruct MinimalDemo{build(){Column(){Text(第一行)Text(第二行)Text(第三行)}}}默认情况下子组件沿垂直方向从上到下排列水平方向居中Column 宽度由最宽的子组件撑开高度由所有子组件累加撑开。3.2 alignItems —— 交叉轴对齐alignItems接收HorizontalAlign枚举值枚举值效果典型场景HorizontalAlign.Start子组件左对齐表单标签、文章正文、信息流卡片HorizontalAlign.Center子组件水平居中默认弹窗、居中按钮组HorizontalAlign.End子组件右对齐操作菜单、金额显示当 Column 宽度设为100%时alignItems效果最明显Column(){Text(左对齐文本).width(200).height(40).backgroundColor(#f0f0f0)Text(也是左对齐).width(150).height(40).backgroundColor(#e0e0e0)}.alignItems(HorizontalAlign.Start).width(100%)3.3 justifyContent —— 主轴分布justifyContent接收FlexAlign枚举值枚举值效果FlexAlign.Start从顶部开始排列默认FlexAlign.Center垂直居中排列FlexAlign.End从底部开始排列FlexAlign.SpaceBetween两端对齐子组件间等距FlexAlign.SpaceAround每个子组件两侧间距相等FlexAlign.SpaceEvenly所有间距含边缘完全相等关键前提justifyContent仅在 Column 高度大于所有子组件高度之和时才生效。3.4 Column 的尺寸控制自适应默认不设置宽高由内容撑开百分比width(100%)/height(50%)固定值width(360)/height(600)layoutWeight按权重分配剩余空间类似 CSS flex-growColumn(){/* A */}.layoutWeight(1)// 占 1/3Column(){/* B */}.layoutWeight(2)// 占 2/3height(0) layoutWeight(1)是撑满剩余空间的经典模式。四、实战 Demo完整代码逐段解析4.1 数据模型ArkTS 严格模式下禁止使用内联对象字面量作为类型声明必须用interface显式定义interfaceInfoItem{title:string;desc:string;}4.2 子组件 InfoCard信息卡片卡片内部同样使用 Column Start 布局Componentstruct InfoCard{title:string;desc:string;index:number0;build(){Column(){Text(this.title).fontSize(16).fontWeight(FontWeight.Bold).fontColor(#1a1a2e).lineHeight(22)Text(this.desc).fontSize(13).fontColor(#666666).lineHeight(20).margin({top:6})}.alignItems(HorizontalAlign.Start)// 卡片内文字左对齐.width(100%).padding(14).backgroundColor(#f8f9fc).borderRadius(10).shadow({radius:4,color:#20000000,offsetX:0,offsetY:2}).margin({bottom:10})}}4.3 子组件 FormRow表单行典型 Column Start 场景标签在上、输入框在下都靠左对齐Componentstruct FormRow{label:string;placeholder:string;Stateprivatevalue:string;build(){Column(){Text(this.label).fontSize(14).fontWeight(500).fontColor(#333333)TextInput({placeholder:this.placeholder,text:this.value}).height(40).width(100%).backgroundColor(#ffffff).borderRadius(6).border({width:1,color:#d9d9d9}).padding({left:12}).onChange((val:string){this.valueval;})}.alignItems(HorizontalAlign.Start).width(100%).margin({bottom:14})}}注意只有State变量可以用private普通输入属性不能加private否则父组件构造函数传值会触发编译警告。4.4 主页面 ColumnStartDemoEntryComponentstruct ColumnStartDemo{StatecurrentJustify:FlexAlignFlexAlign.Start;StateselectedIndex:number0;StatetoastMsg:string;// 自定义通知消息privatereadonlyjustifyOptions:FlexAlign[][FlexAlign.Start,FlexAlign.Center,FlexAlign.End,FlexAlign.SpaceBetween,];privatereadonlyjustifyLabels:string[][Start顶部对齐,Center垂直居中,End底部对齐,SpaceBetween两端等距,];privatereadonlyinfoList:InfoItem[][{title: 系统通知,desc:您的鸿蒙应用已通过安全检测。},{title: 数据报告,desc:本周活跃用户较上周增长 12%。},{title:⚙️ 版本更新,desc:v3.2.0 发布新增 ColumnStart 布局。},];privateswitchJustify(index:number):void{this.selectedIndexindex;this.currentJustifythis.justifyOptions[index];this.toastMsg切换至${this.justifyLabels[index]};setTimeout((){this.toastMsg;},2000);}build(){Column(){// ─── 区域 1标题栏 ───Column(){Text( Column alignItems(Start) 布局演示).fontSize(18).fontWeight(FontWeight.Bold).fontColor(#ffffff).lineHeight(26)Text(子组件顶部对齐 · 垂直排列 · 信息流/表单场景).fontSize(12).fontColor(#cce0ff).margin({top:4})}.alignItems(HorizontalAlign.Start).width(100%).padding(16).backgroundColor(#2d5f8a).borderRadius({bottomLeft:16,bottomRight:16})// ─── 区域 2justifyContent 切换按钮 ───Row(){ForEach(this.justifyLabels,(label:string,idx:number){Column(){Text(label).fontSize(11).fontColor(this.selectedIndexidx?#3a7bd5:#666).fontWeight(this.selectedIndexidx?FontWeight.Bold:FontWeight.Normal).textAlign(TextAlign.Center).lineHeight(16)}.width(80).height(48).justifyContent(FlexAlign.Center).backgroundColor(this.selectedIndexidx?#e6f0ff:#f5f5f5).borderRadius(8).border({width:this.selectedIndexidx?1.5:1,color:this.selectedIndexidx?#3a7bd5:#e0e0e0,}).onClick((){this.switchJustify(idx);})},(item:string)item)}.width(100%).justifyContent(FlexAlign.SpaceEvenly).padding({top:12,bottom:8,left:8,right:8})// ─── 区域 3核心演示区Column Start 可切换 justifyContent ───Column(){// 信息流列表Text( 信息流列表).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#1a1a2e).margin({bottom:8})ForEach(this.infoList,(item:InfoItem,idx:number){InfoCard({title:item.title,desc:item.desc,index:idx})},(item:InfoItem)item.title)Divider().height(1).width(100%).color(#e8e8e8).margin({top:6,bottom:14})// 用户反馈表单Text( 用户反馈表单).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#1a1a2e).margin({bottom:10})FormRow({label: 联系人,placeholder:请输入您的姓名})FormRow({label: 手机号,placeholder:请输入手机号码})FormRow({label: 邮箱,placeholder:请输入邮箱地址})Button(提交反馈).width(100%).height(42).backgroundColor(#3a7bd5).fontColor(#ffffff).borderRadius(10).fontSize(15).fontWeight(FontWeight.Medium).margin({top:4}).onClick((){this.toastMsg✅ 反馈已提交演示;setTimeout((){this.toastMsg;},2000);})}// ★ 核心布局属性.alignItems(HorizontalAlign.Start)// 交叉轴左对齐.justifyContent(this.currentJustify)// 主轴分布可动态切换.width(100%).height(0).layoutWeight(1).padding(14).backgroundColor(#ffffff).borderRadius(12).margin({left:12,right:12,top:10,bottom:12}).shadow({radius:6,color:#1a000000,offsetX:0,offsetY:2})// ─── 区域 4底部通知栏 ───Text(this.toastMsg).fontSize(14).fontColor(#ffffff).backgroundColor(#3a7bd5).width(90%).textAlign(TextAlign.Center).padding({top:10,bottom:10}).borderRadius(20).position({x:5%,bottom:30}).opacity(this.toastMsg.length0?1.0:0.0).animation({duration:300})}.width(100%).height(100%).backgroundColor(#eef2f7)}}4.5 关键布局技巧height(0) layoutWeight(1)layoutWeight类似 CSS 的flex-grow。当父容器高度固定时子 Column 设置layoutWeight(1)会占用剩余高度。height(0)确保从零开始分配。动态justifyContent点击切换按钮更新State currentJustify框架自动触发 Column 重绘子组件位置实时变化。自定义通知替代 showToast用State toastMsgText组件实现。消息为空时opacity: 0设置后显示setTimeout2 秒后清空。.animation({ duration: 300 })提供淡入淡出过渡。五、ForEach 的正确使用ForEach(this.infoList,(item:InfoItem,idx:number){InfoCard({title:item.title,desc:item.desc,index:idx})},(item:InfoItem)item.title// 键值唯一且稳定)第三个参数是键值生成函数帮助框架追踪子组件身份对列表 diff 和复用至关重要。六、ArkTS 严格模式避坑指南6.1 对象字面量不能作为类型声明ERROR: Object literals cannot be used as type declarations// ❌ 错误privatereadonlyinfoList:{title:string;desc:string}[][...];// ✅ 正确interfaceInfoItem{title:string;desc:string;}privatereadonlyinfoList:InfoItem[][...];6.2 私有属性不能通过构造函数初始化// ❌ 错误输入属性用 privateComponentstruct InfoCard{privatetitle:string;}// ✅ 正确去掉 privateComponentstruct InfoCard{title:string;}例外State private value是内部状态可不通过构造函数传值允许用private。6.3 showToast 弃用与异常处理promptAction.showToast在 API 24 中已弃用且可能抛出异常。推荐用纯 ArkUI 组件实现通知提示——如本文 Demo 使用State toastMsgText组件 setTimeout自动隐藏。七、布局性能优化长列表用 List数据量超过 20 项时List支持懒加载比Column更高效。避免不必要的 State不需要参与 UI 渲染的数据用普通成员变量。使用 animation.opacity().animation({ duration: 300 })为布局变化添加平滑过渡。八、从其他平台迁移对照CSS FlexboxArkUIAndroidSwiftUIflex-direction: columnColumn()orientationverticalVStackalign-items: flex-start.alignItems(Start)gravityleftalignment: .leadingjustify-content: flex-start.justifyContent(Start)——justify-content: space-between.justifyContent(SpaceBetween)——flex-grow: 1.layoutWeight(1)layout_weightSpacer()gap.space()/.margin()—spacing——match_parent.width(100%)九、总结与进阶核心要点Column是 ArkUI 最常用的垂直布局容器主轴垂直交叉轴水平alignItems(Start)将所有子组件左对齐是构建表单和列表的基石justifyContent控制垂直分布6 种枚举值满足不同排列需求height(0) layoutWeight(1)是撑满剩余空间的推荐模式ArkTS 严格模式要求显式定义类型内联对象字面量不被允许弃用 API应尽早替换用State 自定义组件替代showToast进阶路径方向组件/API说明弹性布局FlexColumn/Row 的父类滚动列表ListListItem长列表性能优化网格布局GridGridItem相册、商品展示层叠布局Stack悬浮按钮、遮罩层响应式MediaQueryGridRow折叠屏适配动画.animation().transition()页面过渡效果Column alignItems(Start)是 ArkUI 最基础的布局模式。掌握它之后你可以构建绝大多数 UI 页面。本文通过完整 Demo从数据模型、子组件设计、状态管理到布局属性配置全方位展示了这一模式的实际用法。
鸿蒙原生 ArkTS 布局详解:Column + alignItems(ItemAlign.Start) 垂直排列实战
发布时间:2026/6/10 17:36:15
一、引言HarmonyOS NEXT 是华为全栈自研的操作系统ArkTS 是其原生开发语言。ArkUI 提供声明式布局能力Column是其中使用频率最高的组件。本文以Column alignItems(ItemAlign.Start)布局模式为核心通过实战 Demo 讲解Column 的基本原理与属性alignItems交叉轴对齐控制justifyContent主轴分布策略ArkTS 严格模式的常见编译错误与解决方案二、ArkUI 布局体系概述2.1 布局容器三剑客容器主轴方向交叉轴适用场景Column垂直从上到下水平纵向列表、表单、文章详情Row水平从左到右垂直导航栏、按钮组、标签行Stack层叠Z 轴无悬浮按钮、遮罩层、重叠布局2.2 主轴与交叉轴理解 Column 的关键在于分清主轴Main Axis和交叉轴Cross AxisColumn ┌─────────────────────┐ │ 主轴垂直↓ │ │ ┌───────┐ │ │ │ 子组件A │←交叉轴→ │ │ └───────┘ │ │ ┌───────┐ │ │ │ 子组件B │ │ │ └───────┘ │ └─────────────────────┘Column 的两个核心属性分别控制这两个轴Column(){...}.alignItems(HorizontalAlign.Start)// 控制交叉轴水平对齐.justifyContent(FlexAlign.Start)// 控制主轴垂直分布三、Column 容器深度解析3.1 基本用法EntryComponentstruct MinimalDemo{build(){Column(){Text(第一行)Text(第二行)Text(第三行)}}}默认情况下子组件沿垂直方向从上到下排列水平方向居中Column 宽度由最宽的子组件撑开高度由所有子组件累加撑开。3.2 alignItems —— 交叉轴对齐alignItems接收HorizontalAlign枚举值枚举值效果典型场景HorizontalAlign.Start子组件左对齐表单标签、文章正文、信息流卡片HorizontalAlign.Center子组件水平居中默认弹窗、居中按钮组HorizontalAlign.End子组件右对齐操作菜单、金额显示当 Column 宽度设为100%时alignItems效果最明显Column(){Text(左对齐文本).width(200).height(40).backgroundColor(#f0f0f0)Text(也是左对齐).width(150).height(40).backgroundColor(#e0e0e0)}.alignItems(HorizontalAlign.Start).width(100%)3.3 justifyContent —— 主轴分布justifyContent接收FlexAlign枚举值枚举值效果FlexAlign.Start从顶部开始排列默认FlexAlign.Center垂直居中排列FlexAlign.End从底部开始排列FlexAlign.SpaceBetween两端对齐子组件间等距FlexAlign.SpaceAround每个子组件两侧间距相等FlexAlign.SpaceEvenly所有间距含边缘完全相等关键前提justifyContent仅在 Column 高度大于所有子组件高度之和时才生效。3.4 Column 的尺寸控制自适应默认不设置宽高由内容撑开百分比width(100%)/height(50%)固定值width(360)/height(600)layoutWeight按权重分配剩余空间类似 CSS flex-growColumn(){/* A */}.layoutWeight(1)// 占 1/3Column(){/* B */}.layoutWeight(2)// 占 2/3height(0) layoutWeight(1)是撑满剩余空间的经典模式。四、实战 Demo完整代码逐段解析4.1 数据模型ArkTS 严格模式下禁止使用内联对象字面量作为类型声明必须用interface显式定义interfaceInfoItem{title:string;desc:string;}4.2 子组件 InfoCard信息卡片卡片内部同样使用 Column Start 布局Componentstruct InfoCard{title:string;desc:string;index:number0;build(){Column(){Text(this.title).fontSize(16).fontWeight(FontWeight.Bold).fontColor(#1a1a2e).lineHeight(22)Text(this.desc).fontSize(13).fontColor(#666666).lineHeight(20).margin({top:6})}.alignItems(HorizontalAlign.Start)// 卡片内文字左对齐.width(100%).padding(14).backgroundColor(#f8f9fc).borderRadius(10).shadow({radius:4,color:#20000000,offsetX:0,offsetY:2}).margin({bottom:10})}}4.3 子组件 FormRow表单行典型 Column Start 场景标签在上、输入框在下都靠左对齐Componentstruct FormRow{label:string;placeholder:string;Stateprivatevalue:string;build(){Column(){Text(this.label).fontSize(14).fontWeight(500).fontColor(#333333)TextInput({placeholder:this.placeholder,text:this.value}).height(40).width(100%).backgroundColor(#ffffff).borderRadius(6).border({width:1,color:#d9d9d9}).padding({left:12}).onChange((val:string){this.valueval;})}.alignItems(HorizontalAlign.Start).width(100%).margin({bottom:14})}}注意只有State变量可以用private普通输入属性不能加private否则父组件构造函数传值会触发编译警告。4.4 主页面 ColumnStartDemoEntryComponentstruct ColumnStartDemo{StatecurrentJustify:FlexAlignFlexAlign.Start;StateselectedIndex:number0;StatetoastMsg:string;// 自定义通知消息privatereadonlyjustifyOptions:FlexAlign[][FlexAlign.Start,FlexAlign.Center,FlexAlign.End,FlexAlign.SpaceBetween,];privatereadonlyjustifyLabels:string[][Start顶部对齐,Center垂直居中,End底部对齐,SpaceBetween两端等距,];privatereadonlyinfoList:InfoItem[][{title: 系统通知,desc:您的鸿蒙应用已通过安全检测。},{title: 数据报告,desc:本周活跃用户较上周增长 12%。},{title:⚙️ 版本更新,desc:v3.2.0 发布新增 ColumnStart 布局。},];privateswitchJustify(index:number):void{this.selectedIndexindex;this.currentJustifythis.justifyOptions[index];this.toastMsg切换至${this.justifyLabels[index]};setTimeout((){this.toastMsg;},2000);}build(){Column(){// ─── 区域 1标题栏 ───Column(){Text( Column alignItems(Start) 布局演示).fontSize(18).fontWeight(FontWeight.Bold).fontColor(#ffffff).lineHeight(26)Text(子组件顶部对齐 · 垂直排列 · 信息流/表单场景).fontSize(12).fontColor(#cce0ff).margin({top:4})}.alignItems(HorizontalAlign.Start).width(100%).padding(16).backgroundColor(#2d5f8a).borderRadius({bottomLeft:16,bottomRight:16})// ─── 区域 2justifyContent 切换按钮 ───Row(){ForEach(this.justifyLabels,(label:string,idx:number){Column(){Text(label).fontSize(11).fontColor(this.selectedIndexidx?#3a7bd5:#666).fontWeight(this.selectedIndexidx?FontWeight.Bold:FontWeight.Normal).textAlign(TextAlign.Center).lineHeight(16)}.width(80).height(48).justifyContent(FlexAlign.Center).backgroundColor(this.selectedIndexidx?#e6f0ff:#f5f5f5).borderRadius(8).border({width:this.selectedIndexidx?1.5:1,color:this.selectedIndexidx?#3a7bd5:#e0e0e0,}).onClick((){this.switchJustify(idx);})},(item:string)item)}.width(100%).justifyContent(FlexAlign.SpaceEvenly).padding({top:12,bottom:8,left:8,right:8})// ─── 区域 3核心演示区Column Start 可切换 justifyContent ───Column(){// 信息流列表Text( 信息流列表).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#1a1a2e).margin({bottom:8})ForEach(this.infoList,(item:InfoItem,idx:number){InfoCard({title:item.title,desc:item.desc,index:idx})},(item:InfoItem)item.title)Divider().height(1).width(100%).color(#e8e8e8).margin({top:6,bottom:14})// 用户反馈表单Text( 用户反馈表单).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#1a1a2e).margin({bottom:10})FormRow({label: 联系人,placeholder:请输入您的姓名})FormRow({label: 手机号,placeholder:请输入手机号码})FormRow({label: 邮箱,placeholder:请输入邮箱地址})Button(提交反馈).width(100%).height(42).backgroundColor(#3a7bd5).fontColor(#ffffff).borderRadius(10).fontSize(15).fontWeight(FontWeight.Medium).margin({top:4}).onClick((){this.toastMsg✅ 反馈已提交演示;setTimeout((){this.toastMsg;},2000);})}// ★ 核心布局属性.alignItems(HorizontalAlign.Start)// 交叉轴左对齐.justifyContent(this.currentJustify)// 主轴分布可动态切换.width(100%).height(0).layoutWeight(1).padding(14).backgroundColor(#ffffff).borderRadius(12).margin({left:12,right:12,top:10,bottom:12}).shadow({radius:6,color:#1a000000,offsetX:0,offsetY:2})// ─── 区域 4底部通知栏 ───Text(this.toastMsg).fontSize(14).fontColor(#ffffff).backgroundColor(#3a7bd5).width(90%).textAlign(TextAlign.Center).padding({top:10,bottom:10}).borderRadius(20).position({x:5%,bottom:30}).opacity(this.toastMsg.length0?1.0:0.0).animation({duration:300})}.width(100%).height(100%).backgroundColor(#eef2f7)}}4.5 关键布局技巧height(0) layoutWeight(1)layoutWeight类似 CSS 的flex-grow。当父容器高度固定时子 Column 设置layoutWeight(1)会占用剩余高度。height(0)确保从零开始分配。动态justifyContent点击切换按钮更新State currentJustify框架自动触发 Column 重绘子组件位置实时变化。自定义通知替代 showToast用State toastMsgText组件实现。消息为空时opacity: 0设置后显示setTimeout2 秒后清空。.animation({ duration: 300 })提供淡入淡出过渡。五、ForEach 的正确使用ForEach(this.infoList,(item:InfoItem,idx:number){InfoCard({title:item.title,desc:item.desc,index:idx})},(item:InfoItem)item.title// 键值唯一且稳定)第三个参数是键值生成函数帮助框架追踪子组件身份对列表 diff 和复用至关重要。六、ArkTS 严格模式避坑指南6.1 对象字面量不能作为类型声明ERROR: Object literals cannot be used as type declarations// ❌ 错误privatereadonlyinfoList:{title:string;desc:string}[][...];// ✅ 正确interfaceInfoItem{title:string;desc:string;}privatereadonlyinfoList:InfoItem[][...];6.2 私有属性不能通过构造函数初始化// ❌ 错误输入属性用 privateComponentstruct InfoCard{privatetitle:string;}// ✅ 正确去掉 privateComponentstruct InfoCard{title:string;}例外State private value是内部状态可不通过构造函数传值允许用private。6.3 showToast 弃用与异常处理promptAction.showToast在 API 24 中已弃用且可能抛出异常。推荐用纯 ArkUI 组件实现通知提示——如本文 Demo 使用State toastMsgText组件 setTimeout自动隐藏。七、布局性能优化长列表用 List数据量超过 20 项时List支持懒加载比Column更高效。避免不必要的 State不需要参与 UI 渲染的数据用普通成员变量。使用 animation.opacity().animation({ duration: 300 })为布局变化添加平滑过渡。八、从其他平台迁移对照CSS FlexboxArkUIAndroidSwiftUIflex-direction: columnColumn()orientationverticalVStackalign-items: flex-start.alignItems(Start)gravityleftalignment: .leadingjustify-content: flex-start.justifyContent(Start)——justify-content: space-between.justifyContent(SpaceBetween)——flex-grow: 1.layoutWeight(1)layout_weightSpacer()gap.space()/.margin()—spacing——match_parent.width(100%)九、总结与进阶核心要点Column是 ArkUI 最常用的垂直布局容器主轴垂直交叉轴水平alignItems(Start)将所有子组件左对齐是构建表单和列表的基石justifyContent控制垂直分布6 种枚举值满足不同排列需求height(0) layoutWeight(1)是撑满剩余空间的推荐模式ArkTS 严格模式要求显式定义类型内联对象字面量不被允许弃用 API应尽早替换用State 自定义组件替代showToast进阶路径方向组件/API说明弹性布局FlexColumn/Row 的父类滚动列表ListListItem长列表性能优化网格布局GridGridItem相册、商品展示层叠布局Stack悬浮按钮、遮罩层响应式MediaQueryGridRow折叠屏适配动画.animation().transition()页面过渡效果Column alignItems(Start)是 ArkUI 最基础的布局模式。掌握它之后你可以构建绝大多数 UI 页面。本文通过完整 Demo从数据模型、子组件设计、状态管理到布局属性配置全方位展示了这一模式的实际用法。