Collapse 折叠面板
使用折叠面板来收纳内容。
基础用法
你可以同时展开多个面板
一致性
与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;
在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。
反馈
操作反馈:通过样式更新和交互效果,让用户清晰地感知自己的操作;
视觉反馈:通过更新或重新排列页面元素来反映当前状态。
效率
简化流程:保持操作流程简单直观;
清晰明确:清晰地表达你的意图,以便用户能够快速理解并做出决定;
易于识别:界面应直截了当,有助于用户识别,并让他们摆脱记忆和回忆。
可控性
决策:可以接受有关操作的建议,但不要为用户做决定;
控制结果:用户应被赋予操作的自由,包括取消、中止或终止当前操作。
vue
<template>
<div class="demo-collapse">
<el-collapse v-model="activeNames" @change="handleChange">
<el-collapse-item title="Consistency" name="1">
<div>
Consistent with real life: in line with the process and logic of real
life, and comply with languages and habits that the users are used to;
</div>
<div>
Consistent within interface: all elements should be consistent, such
as: design style, icons and texts, position of elements, etc.
</div>
</el-collapse-item>
<el-collapse-item title="Feedback" name="2">
<div>
Operation feedback: enable the users to clearly perceive their
operations by style updates and interactive effects;
</div>
<div>
Visual feedback: reflect current state by updating or rearranging
elements of the page.
</div>
</el-collapse-item>
<el-collapse-item title="Efficiency" name="3">
<div>
Simplify the process: keep operating process simple and intuitive;
</div>
<div>
Definite and clear: enunciate your intentions clearly so that the
users can quickly understand and make decisions;
</div>
<div>
Easy to identify: the interface should be straightforward, which helps
the users to identify and frees them from memorizing and recalling.
</div>
</el-collapse-item>
<el-collapse-item title="Controllability" name="4">
<div>
Decision making: giving advices about operations is acceptable, but do
not make decisions for the users;
</div>
<div>
Controlled consequences: users should be granted the freedom to
operate, including canceling, aborting or terminating current
operation.
</div>
</el-collapse-item>
</el-collapse>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import type { CollapseModelValue } from 'element-plus'
const activeNames = ref(['1'])
const handleChange = (val: CollapseModelValue) => {
console.log(val)
}
</script>
隐藏源代码
手风琴
在手风琴模式下,一次只能展开一个面板
通过 accordion
属性来启用手风琴模式。
一致性
与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;
在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。
反馈
操作反馈:通过样式更新和交互效果,让用户清晰地感知自己的操作;
视觉反馈:通过更新或重新排列页面元素来反映当前状态。
效率
简化流程:保持操作流程简单直观;
清晰明确:清晰地表达你的意图,以便用户能够快速理解并做出决定;
易于识别:界面应直截了当,有助于用户识别,并让他们摆脱记忆和回忆。
可控性
决策:可以接受有关操作的建议,但不要为用户做决定;
控制结果:用户应被赋予操作的自由,包括取消、中止或终止当前操作。
vue
<template>
<div class="demo-collapse">
<el-collapse v-model="activeName" accordion>
<el-collapse-item title="Consistency" name="1">
<div>
Consistent with real life: in line with the process and logic of real
life, and comply with languages and habits that the users are used to;
</div>
<div>
Consistent within interface: all elements should be consistent, such
as: design style, icons and texts, position of elements, etc.
</div>
</el-collapse-item>
<el-collapse-item title="Feedback" name="2">
<div>
Operation feedback: enable the users to clearly perceive their
operations by style updates and interactive effects;
</div>
<div>
Visual feedback: reflect current state by updating or rearranging
elements of the page.
</div>
</el-collapse-item>
<el-collapse-item title="Efficiency" name="3">
<div>
Simplify the process: keep operating process simple and intuitive;
</div>
<div>
Definite and clear: enunciate your intentions clearly so that the
users can quickly understand and make decisions;
</div>
<div>
Easy to identify: the interface should be straightforward, which helps
the users to identify and frees them from memorizing and recalling.
</div>
</el-collapse-item>
<el-collapse-item title="Controllability" name="4">
<div>
Decision making: giving advices about operations is acceptable, but do
not make decisions for the users;
</div>
<div>
Controlled consequences: users should be granted the freedom to
operate, including canceling, aborting or terminating current
operation.
</div>
</el-collapse-item>
</el-collapse>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const activeName = ref('1')
</script>
隐藏源代码
自定义标题
除了使用 title
属性,你还可以使用具名插槽来自定义面板标题,这样就可以添加自定义内容,例如图标。
提示
从版本 2.9.10 开始,title
插槽提供了一个 isActive
属性,用于指示当前折叠项是否处于活动状态。
一致性
与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;
在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。
反馈
操作反馈:通过样式更新和交互效果,让用户清晰地感知自己的操作;
视觉反馈:通过更新或重新排列页面元素来反映当前状态。
效率
简化流程:保持操作流程简单直观;
清晰明确:清晰地表达你的意图,以便用户能够快速理解并做出决定;
易于识别:界面应直截了当,有助于用户识别,并让他们摆脱记忆和回忆。
可控性
决策:可以接受有关操作的建议,但不要为用户做决定;
控制结果:用户应被赋予操作的自由,包括取消、中止或终止当前操作。
vue
<template>
<div class="demo-collapse">
<el-collapse accordion>
<el-collapse-item name="1">
<template #title="{ isActive }">
<div :class="['title-wrapper', { 'is-active': isActive }]">
Consistency
<el-icon class="header-icon">
<info-filled />
</el-icon>
</div>
</template>
<div>
Consistent with real life: in line with the process and logic of real
life, and comply with languages and habits that the users are used to;
</div>
<div>
Consistent within interface: all elements should be consistent, such
as: design style, icons and texts, position of elements, etc.
</div>
</el-collapse-item>
<el-collapse-item title="Feedback" name="2">
<div>
Operation feedback: enable the users to clearly perceive their
operations by style updates and interactive effects;
</div>
<div>
Visual feedback: reflect current state by updating or rearranging
elements of the page.
</div>
</el-collapse-item>
<el-collapse-item title="Efficiency" name="3">
<div>
Simplify the process: keep operating process simple and intuitive;
</div>
<div>
Definite and clear: enunciate your intentions clearly so that the
users can quickly understand and make decisions;
</div>
<div>
Easy to identify: the interface should be straightforward, which helps
the users to identify and frees them from memorizing and recalling.
</div>
</el-collapse-item>
<el-collapse-item title="Controllability" name="4">
<div>
Decision making: giving advices about operations is acceptable, but do
not make decisions for the users;
</div>
<div>
Controlled consequences: users should be granted the freedom to
operate, including canceling, aborting or terminating current
operation.
</div>
</el-collapse-item>
</el-collapse>
</div>
</template>
<script setup lang="ts">
import { InfoFilled } from '@element-plus/icons-vue'
</script>
<style scoped>
.title-wrapper {
display: flex;
align-items: center;
gap: 4px;
}
.title-wrapper.is-active {
color: var(--el-color-primary);
}
</style>
隐藏源代码
自定义图标 2.8.3
除了使用 icon
属性外,您还可以通过具名插槽自定义面板项的图标,这使得添加自定义内容成为可能。
一致性
与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;
在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。
反馈折叠
操作反馈:通过样式更新和交互效果,让用户清晰地感知自己的操作;
视觉反馈:通过更新或重新排列页面元素来反映当前状态。
效率
简化流程:保持操作流程简单直观;
清晰明确:清晰地表达你的意图,以便用户能够快速理解并做出决定;
易于识别:界面应直截了当,有助于用户识别,并让他们摆脱记忆和回忆。
可控性
决策:可以接受有关操作的建议,但不要为用户做决定;
控制结果:用户应被赋予操作的自由,包括取消、中止或终止当前操作。
vue
<template>
<div class="demo-collapse">
<el-collapse v-model="activeNames" @change="handleChange">
<el-collapse-item title="Consistency" name="1" :icon="CaretRight">
<div>
Consistent with real life: in line with the process and logic of real
life, and comply with languages and habits that the users are used to;
</div>
<div>
Consistent within interface: all elements should be consistent, such
as: design style, icons and texts, position of elements, etc.
</div>
</el-collapse-item>
<el-collapse-item title="Feedback" name="2">
<template #icon="{ isActive }">
<span class="icon-ele">
{{ isActive ? 'Expanded' : 'Collapsed' }}
</span>
</template>
<div>
Operation feedback: enable the users to clearly perceive their
operations by style updates and interactive effects;
</div>
<div>
Visual feedback: reflect current state by updating or rearranging
elements of the page.
</div>
</el-collapse-item>
<el-collapse-item title="Efficiency" name="3">
<div>
Simplify the process: keep operating process simple and intuitive;
</div>
<div>
Definite and clear: enunciate your intentions clearly so that the
users can quickly understand and make decisions;
</div>
<div>
Easy to identify: the interface should be straightforward, which helps
the users to identify and frees them from memorizing and recalling.
</div>
</el-collapse-item>
<el-collapse-item title="Controllability" name="4">
<div>
Decision making: giving advices about operations is acceptable, but do
not make decisions for the users;
</div>
<div>
Controlled consequences: users should be granted the freedom to
operate, including canceling, aborting or terminating current
operation.
</div>
</el-collapse-item>
</el-collapse>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { CaretRight } from '@element-plus/icons-vue'
import type { CollapseModelValue } from 'element-plus'
const activeNames = ref(['1'])
const handleChange = (val: CollapseModelValue) => {
console.log(val)
}
</script>
<style scoped>
.icon-ele {
margin: 0 8px 0 auto;
color: #409eff;
}
</style>
隐藏源代码
自定义图标位置 2.9.10
使用 expand-icon-position
属性,您可以自定义图标的位置。
展开图标位置
左侧右侧
一致性
与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;
在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。
反馈
操作反馈:通过样式更新和交互效果,让用户清晰地感知自己的操作;
视觉反馈:通过更新或重新排列页面元素来反映当前状态。
效率
简化流程:保持操作流程简单直观;
清晰明确:清晰地表达你的意图,以便用户能够快速理解并做出决定;
易于识别:界面应直截了当,有助于用户识别,并让他们摆脱记忆和回忆。
vue
<template>
<div class="demo-collapse-position">
<div class="flex items-center mb-4">
<span class="mr-4">expand icon position: </span>
<el-switch
v-model="position"
inactive-value="left"
active-value="right"
inactive-text="left"
active-text="right"
style="--el-switch-off-color: #88b8fe"
/>
</div>
<el-collapse :expand-icon-position="position">
<el-collapse-item title="Consistency" name="1">
<div>
Consistent with real life: in line with the process and logic of real
life, and comply with languages and habits that the users are used to;
</div>
<div>
Consistent within interface: all elements should be consistent, such
as: design style, icons and texts, position of elements, etc.
</div>
</el-collapse-item>
<el-collapse-item title="Feedback" name="2">
<div>
Operation feedback: enable the users to clearly perceive their
operations by style updates and interactive effects;
</div>
<div>
Visual feedback: reflect current state by updating or rearranging
elements of the page.
</div>
</el-collapse-item>
<el-collapse-item title="Efficiency" name="3">
<div>
Simplify the process: keep operating process simple and intuitive;
</div>
<div>
Definite and clear: enunciate your intentions clearly so that the
users can quickly understand and make decisions;
</div>
<div>
Easy to identify: the interface should be straightforward, which helps
the users to identify and frees them from memorizing and recalling.
</div>
</el-collapse-item>
</el-collapse>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import type { CollapseIconPositionType } from 'element-plus'
const position = ref<CollapseIconPositionType>('left')
</script>
隐藏源代码
阻止折叠 2.9.11
设置 before-collapse
属性,如果返回 false
或返回一个被拒绝的 Promise
,则会阻止折叠。
折叠前返回
falsetrue
一致性
与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;
在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。
反馈
操作反馈:通过样式更新和交互效果,让用户清晰地感知自己的操作;
视觉反馈:通过更新或重新排列页面元素来反映当前状态。
效率
简化流程:保持操作流程简单直观;
清晰明确:清晰地表达你的意图,以便用户能够快速理解并做出决定;
易于识别:界面应直截了当,有助于用户识别,并让他们摆脱记忆和回忆。
可控性
决策:可以接受有关操作的建议,但不要为用户做决定;
控制结果:用户应被赋予操作的自由,包括取消、中止或终止当前操作。
vue
<template>
<div v-loading="loading" class="demo-collapse">
<div class="flex items-center mb-4">
<span class="mr-4">before collapse return: </span>
<el-switch
v-model="before"
:inactive-value="false"
:active-value="true"
inactive-text="false"
active-text="true"
/>
</div>
<el-collapse v-model="activeNames" :before-collapse="beforeCollapse">
<el-collapse-item title="Consistency" name="1">
<div>
Consistent with real life: in line with the process and logic of real
life, and comply with languages and habits that the users are used to;
</div>
<div>
Consistent within interface: all elements should be consistent, such
as: design style, icons and texts, position of elements, etc.
</div>
</el-collapse-item>
<el-collapse-item title="Feedback" name="2">
<div>
Operation feedback: enable the users to clearly perceive their
operations by style updates and interactive effects;
</div>
<div>
Visual feedback: reflect current state by updating or rearranging
elements of the page.
</div>
</el-collapse-item>
<el-collapse-item title="Efficiency" name="3">
<div>
Simplify the process: keep operating process simple and intuitive;
</div>
<div>
Definite and clear: enunciate your intentions clearly so that the
users can quickly understand and make decisions;
</div>
<div>
Easy to identify: the interface should be straightforward, which helps
the users to identify and frees them from memorizing and recalling.
</div>
</el-collapse-item>
<el-collapse-item title="Controllability" name="4">
<div>
Decision making: giving advices about operations is acceptable, but do
not make decisions for the users;
</div>
<div>
Controlled consequences: users should be granted the freedom to
operate, including canceling, aborting or terminating current
operation.
</div>
</el-collapse-item>
</el-collapse>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const before = ref(true)
const activeNames = ref(['1'])
const loading = ref(false)
const beforeCollapse = (): Promise<boolean> => {
loading.value = true
return new Promise((resolve) => {
setTimeout(() => {
loading.value = false
return resolve(before.value)
}, 1000)
})
}
</script>
隐藏源代码
Collapse API
Collapse 属性
名称 | 描述 | 类型 | 默认值 |
---|---|---|---|
model-value / v-model | 当前激活的面板,手风琴模式下类型为 string ,否则为 array | string / array | [] |
accordion | 是否启用手风琴模式 | boolean | false |
expand-icon-position 2.9.10 | 设置展开图标的位置 | 枚举 | 右侧 |
before-collapse 2.9.11 | 折叠状态改变前的 before-collapse 钩子。如果返回 false 或返回一个被拒绝的 Promise ,将停止折叠 | Function | — |
Collapse 事件
名称 | 描述 | 类型 |
---|---|---|
change | 当激活面板改变时触发,手风琴模式下参数类型为 string ,否则为 array | Function |
Collapse 插槽
名称 | 描述 | 子标签 |
---|---|---|
default | 自定义默认内容 | Collapse Item |
Collapse Exposes
名称 | 描述 | 类型 |
---|---|---|
activeNames | 当前激活面板的名称 | object |
setActiveNames | 设置激活的面板名称 | Function |
Collapse Item API
Collapse Item 属性
名称 | 描述 | 类型 | 默认值 |
---|---|---|---|
名称 | 面板的唯一标识 | string / number | — |
title | 面板的标题 | string | '' |
icon 2.8.3 | 折叠项的图标 | string / Component | ArrowRight |
disabled | 禁用折叠项 | boolean | false |
Collapse Item 插槽
名称 | 描述 | 类型 |
---|---|---|
default | Collapse Item 的内容 | — |
title | Collapse Item 标题的内容 | object |
icon 2.8.3 | Collapse Item 图标的内容 | object |
Collapse Item Exposes
名称 | 描述 | 类型 |
---|---|---|
isActive | 当前折叠项是否处于活动状态 | object |