Skip to content

引入组件

局部引入

ts
// parent.vue
const FCollapse = defineAsyncComponent(() => import('@/components/formaui/f-collapse/f-collapse.vue'))

基础用法

手风琴模式:通过 indexactiveIndex 控制展开项

html
<f-collapse :index="0" :active-index="activeIndex" @click="onClick">
  <template #title>
    <f-cell :show-arrow="false" :show-line="false">标题一</f-cell>
  </template>
  <template #content>
    <view class="px-4 py-3">折叠面板内容一</view>
  </template>
</f-collapse>
ts
import { ref } from 'vue'

const activeIndex = ref(0)

const onClick = (detail: { index: number }) => {
  activeIndex.value = detail.index
}

点击切换展开/收起

ts
const onToggleClick = (detail: { index: number }) => {
  toggleIndex.value = toggleIndex.value === detail.index ? -1 : detail.index
}

disabled属性:禁用(默认false

html
<f-collapse :index="0" :active-index="activeIndex" disabled>
  <template #title>
    <f-cell :show-arrow="false" :show-line="false">禁用状态</f-cell>
  </template>
  <template #content>
    <view class="px-4 py-3">不可点击</view>
  </template>
</f-collapse>

showArrow属性:是否显示箭头(默认true

html
<f-collapse :index="0" :active-index="activeIndex" :show-arrow="false" />

headerBgColor / bodyBgColor属性:自定义背景色

html
<f-collapse header-bg-color="#F5F7FA" body-bg-color="#F5F7FA" />

height属性:展开高度(默认auto

固定高度时使用具体值,如 height="200rpx"

插槽

名称说明
title标题区域
content折叠内容

属性

名称类型说明默认值
bgColorstring面板背景颜色transparent
headerBgColorstring标题栏背景颜色#FFFFFF
bodyBgColorstring内容区背景颜色transparent
heightstring展开时内容区高度,auto 自适应auto
indexnumber面板索引0
activeIndexnumber当前展开的面板索引,相等时展开-1
disabledboolean是否禁用false
showArrowboolean是否显示箭头true
arrowColorstring箭头颜色#0B1D4A

事件

事件名说明回调参数
click点击标题栏时{ index }

方法

方法名说明传入参数
---