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

Collapse

\n

Intro

\n

Place a group of content in multiple collapsible panels, click the title of the panel to expand or contract its content.

\n

Install

\n

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

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

Usage

\n

Basic Usage

\n

Use v-model to control the name of active panels.

\n
<van-collapse v-model="activeNames">\n  <van-collapse-item title="Title1" name="1">\n    The code is written for people to see and can be run on a machine.\n  </van-collapse-item>\n  <van-collapse-item title="Title2" name="2">\n    Technology is nothing more than the common soul of those who develop it.\n  </van-collapse-item>\n  <van-collapse-item title="Title3" name="3">\n    The frequency of people swearing during code reading is the only measure of\n    code quality.\n  </van-collapse-item>\n</van-collapse>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const activeNames = ref(['1']);\n    return { activeNames };\n  },\n};\n
\n

Accordion

\n

In accordion mode, only one panel can be expanded at the same time.

\n
<van-collapse v-model="activeName" accordion>\n  <van-collapse-item title="Title1" name="1">\n    The code is written for people to see and can be run on a machine.\n  </van-collapse-item>\n  <van-collapse-item title="Title2" name="2">\n    Technology is nothing more than the common soul of those who develop it.\n  </van-collapse-item>\n  <van-collapse-item title="Title3" name="3">\n    The frequency of people swearing during code reading is the only measure of\n    code quality.\n  </van-collapse-item>\n</van-collapse>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const activeName = ref('1');\n    return { activeName };\n  },\n};\n
\n

Disabled

\n

Use the disabled prop to disable CollapseItem.

\n
<van-collapse v-model="activeNames">\n  <van-collapse-item title="Title1" name="1">\n    The code is written for people to see and can be run on a machine.\n  </van-collapse-item>\n  <van-collapse-item title="Title2" name="2" disabled>\n    Technology is nothing more than the common soul of those who develop it.\n  </van-collapse-item>\n  <van-collapse-item title="Title3" name="3" disabled>\n    The frequency of people swearing during code reading is the only measure of\n    code quality.\n  </van-collapse-item>\n</van-collapse>\n
\n

Custom title

\n

Using title slot to custom title.

\n
<van-collapse v-model="activeNames">\n  <van-collapse-item name="1">\n    <template #title>\n      <div>Title1 <van-icon name="question-o" /></div>\n    </template>\n    The code is written for people to see and can be run on a machine.\n  </van-collapse-item>\n  <van-collapse-item title="Title2" name="2" icon="shop-o">\n    Technology is nothing more than the common soul of those who develop it.\n  </van-collapse-item>\n</van-collapse>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const activeNames = ref(['1']);\n    return { activeNames };\n  },\n};\n
\n

Toggle All

\n

Using toggleAll method to toggle all items.

\n
<van-collapse v-model="activeNames" ref="collapse">\n  <van-collapse-item title="Title1" name="1">\n    The code is written for people to see and can be run on a machine.\n  </van-collapse-item>\n  <van-collapse-item title="Title2" name="2">\n    Technology is nothing more than the common soul of those who develop it.\n  </van-collapse-item>\n  <van-collapse-item title="Title3" name="3">\n    The frequency of people swearing during code reading is the only measure of\n    code quality.\n  </van-collapse-item>\n</van-collapse>\n\n<van-button type="primary" @click="openAll">Open All</van-button>\n<van-button type="primary" @click="toggleAll">Toggle All</van-button>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const activeNames = ref(['1']);\n    const collapse = ref(null);\n\n    const openAll = () => {\n      collapse.value.toggleAll(true);\n    }\n    const toggleAll = () => {\n      collapse.value.toggleAll();\n    },\n\n    return {\n      activeNames,\n      openAll,\n      toggleAll,\n      collapse,\n    };\n  },\n};\n
\n
\n

Tips: The toggleAll method cannot be used in accordion mode.

\n
\n

API

\n

Collapse 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
AttributeDescriptionTypeDefault
v-modelNames of current active panelsaccordion mode: number | string
non-accordion mode: (number | string)[]
-
accordionWhether to be accordion modebooleanfalse
borderWhether to show outer borderbooleantrue
\n

Collapse Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
EventDescriptionArguments
changeEmitted when switching panelactiveNames: string | number | Array<string | number>
\n

CollapseItem 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\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
nameNamenumber | stringindex
iconLeft Iconstring-
sizeTitle size, can be set to largestring-
titleTitlenumber | string-
valueRight textnumber | string-
labelDescription below the titlestring-
borderWhether to show inner borderbooleantrue
disabledWhether to disabled collapsebooleanfalse
readonlyWhether to be readonlybooleanfalse
is-linkWhether to show link iconbooleantrue
lazy-renderWhether to lazy render util openedbooleantrue
title-classTitle classNamestring-
value-classValue classNamestring-
label-classLabel classNamestring-
\n

Collapse Methods

\n

Use ref to get Collapse 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
toggleAllToggle the expanded status of all collapsesoptions?: boolean | object-
\n

toggleAll Usage

\n
import { ref } from 'vue';\nimport type { CollapseInstance } from 'vant';\n\nconst collapseRef = ref<CollapseInstance>();\n\n// Toggle all\ncollapseRef.value?.toggleAll();\n// Expand all\ncollapseRef.value?.toggleAll(true);\n// UnExpand all\ncollapseRef.value?.toggleAll(false);\n\n// Toggle all, skip disabled\ncollapseRef.value?.toggleAll({\n  skipDisabled: true,\n});\n// Expand all, skip disabled\ncollapseRef.value?.toggleAll({\n  expanded: true,\n  skipDisabled: true,\n});\n
\n

CollapseItem Methods

\n

Use ref to get CollapseItem 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

Types

\n

The component exports the following type definitions:

\n
import type {\n  CollapseProps,\n  CollapseItemProps,\n  CollapseItemInstance,\n  CollapseToggleAllOptions,\n} from 'vant';\n
\n

CollapseItemInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { CollapseItemInstance } from 'vant';\n\nconst collapseItemRef = ref<CollapseItemInstance>();\n\ncollapseItemRef.value?.toggle();\n
\n

CollapseItem Slots

\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
NameDescription
defaultContent
titleCustom header title
valueCustom header value
labelCustom header label
iconCustom header left icon
right-iconCustom header right icon
\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\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
NameDefault ValueDescription
--van-collapse-item-durationvar(--van-duration-base)-
--van-collapse-item-content-paddingvar(--van-padding-sm) var(--van-padding-md)-
--van-collapse-item-content-font-sizevar(--van-font-size-md)-
--van-collapse-item-content-line-height1.5-
--van-collapse-item-content-text-colorvar(--van-text-color-2)-
--van-collapse-item-content-backgroundvar(--van-background-2)-
--van-collapse-item-title-disabled-colorvar(--van-text-color-3)-
\n
'},null,8,l))}}}]);