Collapse 折叠面板

可以折叠/展开的内容区域。

何时使用

  • 对复杂区域进行分组和隐藏,保持页面的整洁。
  • 手风琴 是一种特殊的折叠面板,只允许单个内容区域展开。

代码演示

折叠面板

可以同时展开多个面板,这个例子默认展开了第一个。

  1. <template>
  2. <v-collapse @change="onChange" v-model="activeIndex">
  3. <v-panel header="This is panel header 1" index="1">
  4. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  5. </v-panel>
  6. <v-panel header="This is panel header 2" index="2">
  7. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  8. </v-panel>
  9. <v-panel header="This is panel header 3" index="3">
  10. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  11. </v-panel>
  12. </v-collapse>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. activeIndex:['1'],
  19. }
  20. },
  21. methods: {
  22. onChange(index, status) {
  23. console.log(`第${index}个面板发生变化,目前状态: ${status}`);
  24. },
  25. },
  26. watch: {
  27. activeIndex(val){
  28. console.log(val);
  29. },
  30. },
  31. }
  32. </script>

手风琴

手风琴,每次只打开一个tab。

  1. <template>
  2. <v-collapse @change="onChange" accordion :active-index="activeIndexMore">
  3. <v-panel header="This is panel header 1" index="1">
  4. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  5. </v-panel>
  6. <v-panel header="This is panel header 2" index="2">
  7. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  8. </v-panel>
  9. <v-panel header="This is panel header 3" index="3">
  10. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  11. </v-panel>
  12. </v-collapse>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. accordionActiveIndex:['1','2'],
  19. }
  20. },
  21. methods: {
  22. onChange(index, status) {
  23. console.log(`第${index}个面板发生变化,目前状态: ${status}`);
  24. },
  25. },
  26. watch: {
  27. accordionActiveIndex(val){
  28. console.log(val);
  29. },
  30. },
  31. }
  32. </script>

嵌套模式

可在单个面板里面嵌套

  1. <template>
  2. <v-collapse @change="onChange" :active-index="activeIndexMore">
  3. <v-panel header="This is panel header 1" index="1">
  4. <v-collapse :active-index="activeIndexMore">
  5. <v-panel header="This is panel header 1-1" index="1">
  6. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  7. </v-panel>
  8. <v-panel header="This is panel header 1-2" index="2">
  9. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  10. </v-panel>
  11. </v-collapse>
  12. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  13. </v-panel>
  14. <v-panel header="This is panel header 2" index="2">
  15. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  16. </v-panel>
  17. <v-panel header="This is panel header 3" index="3">
  18. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  19. </v-panel>
  20. </v-collapse>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. activeIndexMore:['1'],
  27. }
  28. },
  29. methods: {
  30. onChange(index, status) {
  31. console.log(`第${index}个面板发生变化,目前状态: ${status}`);
  32. },
  33. },
  34. }
  35. </script>

简洁风格

一套没有边框的简洁样式

  1. <template>
  2. <v-collapse @change="onChange" :active-index="activeIndexSimple" :bordered="false">
  3. <v-panel header="This is panel header 1" index="1">
  4. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  5. </v-panel>
  6. <v-panel header="This is panel header 2" index="2">
  7. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  8. </v-panel>
  9. <v-panel header="This is panel header 3" index="3">
  10. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  11. </v-panel>
  12. </v-collapse>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. activeIndexSimple:['1'],
  19. }
  20. },
  21. methods: {
  22. onChange(index, status) {
  23. console.log(`第${index}个面板发生变化,目前状态: ${status}`);
  24. },
  25. },
  26. }
  27. </script>

自定义面板

自定义各个面板的头部、背景色、圆角和边距。

  1. <template>
  2. <v-collapse @change="onChange" :active-index="activeIndexMore" :bordered="false">
  3. <v-panel index="1" :style="customPanelStyle">
  4. <v-button type="primary" icon="search" slot="header"><span>搜索</span></v-button>
  5. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  6. </v-panel>
  7. <v-panel header="This is panel header 2" index="2" :style="customPanelStyle">
  8. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  9. </v-panel>
  10. <v-panel header="This is panel header 3" index="3" :style="customPanelStyle">
  11. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
  12. </v-panel>
  13. </v-collapse>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. activeIndexMore:['1'],
  20. customPanelStyle: {
  21. background: '#f7f7f7',
  22. borderRadius: '4px',
  23. marginBottom: '24px',
  24. border: 0,
  25. },
  26. }
  27. },
  28. methods: {
  29. onChange(index, status) {
  30. console.log(`第${index}个面板发生变化,目前状态: ${status}`);
  31. },
  32. },
  33. }
  34. </script>

API

Collapse Props

成员说明类型默认值
activeIndex当前展开状态,可用v-modelArray[]
accordion开启手风琴模式Booleanfalse
bordered开启简洁模式Booleanfalse

Collapse Events

事件说明回调参数
change展开-收起时触发index, status

Collapse Panel Props

成员说明类型默认值
index当前索引Number[]
header标题内容String
slot:header自定义标题内容Slot Node