Ellipsis
文字省略:多行 CSS line-clamp 優先(行數由 --lh-ellipsis-rows CSS 變數驅動),position="middle" 走 JS 截斷(truncateMiddle,全端一致)。服務展開/收起、中段省略與自訂 action 場景。
平台差異(登記):本端無平台特化——end 走各端 CSS 引擎均支援的 -webkit-line-clamp,middle 走 share core 的 truncateMiddle JS 截斷;截斷與狀態換算全部复用 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 字摘要。

