Ellipsis 文本省略
文本省略:多行 CSS line-clamp 优先(行数由 --lh-ellipsis-rows CSS 变量驱动), position="middle" 走 JS 截断(truncateMiddle,全端一致)。服务展开/收起、 中段省略与自定义 action 场景(单行纯省略仍用 Text 组件的 ellipsis)。
平台差异(登记):本端无平台特化——end 位置走各端 CSS 引擎均支持的
-webkit-line-clamp,middle 位置走 share core 的truncateMiddleJS 截断; 截断与状态换算全部复用 share core 纯函数。
基础用法
vue
<template>
<lh-ellipsis :content="longText" />
<lh-ellipsis :content="longText" :rows="2" />
<lh-ellipsis :content="longText" position="middle" />
</template>
<script setup lang="ts">
const longText = 'lh-ui 是一个跨端组件库家族,双血脉架构,八仓齐发,文档站十站齐备'
</script>受控展开
expanded 传入即受控(v-model:expanded);change 在每次 action 点击时触发:
vue
<lh-ellipsis :content="longText" :rows="2" expandable v-model:expanded="open" />Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| content | 文本内容 | string | — |
| rows | 折叠时可见行数(>= 1;非法值归一为 1) | number | 1 |
| expandable | 渲染展开 / 收起 action | boolean | false |
| expanded | 展开态(受控;不传则内部自管) | boolean | — |
| actionText | action 文案(未传走 i18n ellipsis.expand / collapse) | string | — |
| position | 截断位置:end 走 CSS line-clamp;middle 走单行 JS 截断 | 'end' | 'middle' | 'end' |
| ellipsisLabel | 无障碍标签(未传取内容前 40 字摘要) | string | — |
| customClass | 自定义类名(透传到根节点) | string | — |
| sx | sx 快速布局属性 | LhSxProps | — |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| update:expanded | 展开态回写(v-model:expanded) | expanded: boolean |
| change | 展开态变化 | expanded: boolean |
| clickAction | action 点击(与 change 同时触发) | — |
无障碍
action 为独立可聚焦节点(role="button"),aria-expanded 随展开态同步; 根节点 aria-label 默认取内容前 40 字摘要。

