Skip to content

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)number1
expandable渲染展開 / 收起 actionbooleanfalse
expanded展開態(受控;不傳則 內部自管)boolean—
actionTextaction 文案(未傳走 i18n ellipsis.expand / collapse)string—
position截斷位置:end 走 CSS line-clamp;middle 走單行 JS 截斷'end' | 'middle''end'
ellipsisLabel無障礙標籤(未傳取內容前 40 字摘要)string—
customClass自訂類名(透傳到根節點)string—
sxsx 快速佈局屬性LhSxProps—

Events ​

事件說明回調參數
update:expanded展開態回寫(v-model:expanded)expanded: boolean
change展開態變化expanded: boolean
clickActionaction 點擊(與 change 同時觸發)—

無障礙 ​

  • action 為獨立可聚焦節點(role="button"),aria-expanded 隨展開態同步;根節點 aria-label 預設取內容前 40 字摘要。