/*! For license information please see 3683.b85c1268.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["3683"],{94621:function(s,n,t){"use strict";t.r(n);var a=t("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

TextEllipsis

\n

Intro

\n

Display ellipsis for long text and support for expanding or collapsing text. Please upgrade vant to >= v4.1.0 before using this component.

\n

Install

\n

Register component globally via app.use, refer to Component Registration for more registration ways.

\n
import { createApp } from 'vue';\nimport { TextEllipsis } from 'vant';\n\nconst app = createApp();\napp.use(TextEllipsis);\n
\n

Usage

\n

Basic Usage

\n

Show one rows by default.

\n
<van-text-ellipsis :content="text" />\n
\n
export default {\n  setup() {\n    const text =\n      'Take your time and be patient. Life itself will eventually answer all those questions it once raised for you.';\n    return { text };\n  },\n};\n
\n

Expand/Collapse

\n

Support Expand/Collapse.

\n
<van-text-ellipsis\n  :content="text"\n  expand-text="expand"\n  collapse-text="collapse"\n/>\n
\n
export default {\n  setup() {\n    const text =\n      "The fleeting time of one's life is everything that belongs to a person. Only this thing truly belongs to you. Everything else is just a momentary pleasure or misfortune, which will soon be gone with the passing of time.";\n    return { text };\n  },\n};\n
\n

Customize rows

\n

Display the number of rows by setting rows.

\n
<van-text-ellipsis\n  rows="3"\n  :content="text"\n  expand-text="expand"\n  collapse-text="collapse"\n/>\n
\n
export default {\n  setup() {\n    const text =\n      "That day, I turned twenty-one. In the golden age of my life, I was full of dreams. I wanted to love, to eat, and to instantly transform into one of these clouds, part alight, part darkened. It was only later that I understood life is but a slow, drawn-out process of getting your balls crushed. Day by day, you get older. Day by day, your dreams fade. In the end you are no different from a crushed ox. But I hadn't foreseen any of it on my twenty-first birthday. I thought I would be vigorous forever, and that nothing could ever crush me.";\n    return { text };\n  },\n};\n
\n

Custom Collapse Position

\n\n
<van-text-ellipsis\n  rows="1"\n  :content="text"\n  expand-text="expand"\n  collapse-text="collapse"\n  position="start"\n/>\n
\n
export default {\n  setup() {\n    const text =\n      "That day, I turned twenty-one. In the golden age of my life, I was full of dreams. I wanted to love, to eat, and to instantly transform into one of these clouds, part alight, part darkened. It was only later that I understood life is but a slow, drawn-out process of getting your balls crushed. Day by day, you get older. Day by day, your dreams fade. In the end you are no different from a crushed ox. But I hadn't foreseen any of it on my twenty-first birthday. I thought I would be vigorous forever, and that nothing could ever crush me.";\n    return { text };\n  },\n};\n
\n\n
<van-text-ellipsis\n  rows="2"\n  :content="text"\n  expand-text="expand"\n  collapse-text="collapse"\n  position="middle"\n/>\n
\n
export default {\n  setup() {\n    const text =\n      "That day, I turned twenty-one. In the golden age of my life, I was full of dreams. I wanted to love, to eat, and to instantly transform into one of these clouds, part alight, part darkened. It was only later that I understood life is but a slow, drawn-out process of getting your balls crushed. Day by day, you get older. Day by day, your dreams fade. In the end you are no different from a crushed ox. But I hadn't foreseen any of it on my twenty-first birthday. I thought I would be vigorous forever, and that nothing could ever crush me.";\n    return { text };\n  },\n};\n
\n

Custom Action

\n

Use action slots to custom action.

\n
<van-text-ellipsis :content="text">\n  <template #action="{ expanded }">\n    {{ expanded ? 'Collapse' : 'Expand' }}\n  </template>\n</van-text-ellipsis>\n
\n
export default {\n  setup() {\n    const text =\n      'Take your time and be patient. Life itself will eventually answer all those questions it once raised for you.';\n    return { text };\n  },\n};\n
\n

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
rowsNumber of rows displayednumber | string1
contentThe text displayedstring-
expand-textExpand operation textstring-
collapse-textCollapse operation textstring-
dots v4.2.0Text content of ellipsisstring\'...\'
position v4.6.2Can be set to start middlestring\'end\'
\n

Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
EventDescriptionArguments
click-actionEmitted when Expand/Collapse is clickedevent: MouseEvent
\n

Methods

\n

Use ref to get TextEllipsis instance and call instance methods.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionAttributeReturn value
toggleToggle expanded statusexpanded?: boolean-
\n

Slots

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionSlotProps
action v4.8.3Custom action{ expanded: boolean }
\n

Types

\n

The component exports the following type definitions:

\n
import type {\n  TextEllipsisProps,\n  TextEllipsisInstance,\n  TextEllipsisThemeVars,\n} from 'vant';\n
\n

TextEllipsisInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { TextEllipsisInstance } from 'vant';\n\nconst textEllipsisRef = ref<TextEllipsisInstance>();\n\ntextEllipsisRef.value?.toggle();\n
\n

Theming

\n

CSS Variables

\n

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDefault ValueDescription
--van-text-ellipsis-action-colorvar(--van-blue)Color of action text
--van-text-ellipsis-line-height1.6Line height of text
\n
'},null,8,e))}}}]);