Skip to content
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

Collapse 折叠面板

通过折叠面板收纳内容区域

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

html
<template>
  <up-collapse
    @change="change"
    @close="close"
    @open="open"
  >
    <up-collapse-item
      title="文档指南"
      name="Docs guide"
    >
      <text class="u-collapse-content">涵盖uniapp各个方面,给开发者方向指导和设计理念,让您茅塞顿开,一马平川</text>
    </up-collapse-item>
    <up-collapse-item
      title="组件全面"
      name="Variety components"
    >
      <text class="u-collapse-content">众多组件覆盖开发过程的各个需求,组件功能丰富,多端兼容。让您快速集成,开箱即用</text>
    </up-collapse-item>
    <up-collapse-item
      title="众多利器"
      name="Numerous tools"
    >
      <text class="u-collapse-content">众多的贴心小工具,是您开发过程中召之即来的利器,让您飞镖在手,百步穿杨</text>
    </up-collapse-item>
  </up-collapse>
</template>

<script>
	export default {
		methods: {
            open(e) {
              // console.log('open', e)
            },
            close(e) {
              // console.log('close', e)
            },
            change(e) {
              // console.log('change', e)
            }
        }
	}
</script>

控制面板的初始状态,以及是否可以操作

  • 设置u-collapse-itemname参数,并在u-collapse中指定数组value可以让面板初始化时为打开状态
  • 如果设置u-collapse-itemdisabled参数,那么面板会保持被禁用状态
html
<template>
  <up-collapse
    :value="['2']"
  >
    <up-collapse-item
      title="文档指南"
    >
      <text class="u-collapse-content">涵盖uniapp各个方面,给开发者方向指导和设计理念,让您茅塞顿开,一马平川</text>
    </up-collapse-item>
    <up-collapse-item
      disabled
      title="组件全面"
    >
      <text class="u-collapse-content">众多组件覆盖开发过程的各个需求,组件功能丰富,多端兼容。让您快速集成,开箱即用</text>
    </up-collapse-item>
    <up-collapse-item
      name="2"
      title="众多利器"
    >
      <text class="u-collapse-content">众多的贴心小工具,是您开发过程中召之即来的利器,让您飞镖在手,百步穿杨</text>
    </up-collapse-item>
  </up-collapse>
</template>

<script>
  export default {
    methods: {
      open(e) {
        // console.log('open', e)
      },
      close(e) {
        // console.log('close', e)
      },
      change(e) {
        // console.log('change', e)
      }
    }
  }
</script>

手风琴模式

  • u-collapseaccordion设置为true,这样可以开启手风琴模式
html
<template>
    <view class="u-page__item">
        <text class="u-page__item__title">手风琴模式</text>
        <up-collapse
                accordion
        >
            <up-collapse-item
                    title="文档指南"
            >
                <text class="u-collapse-content">涵盖uniapp各个方面,给开发者方向指导和设计理念,让您茅塞顿开,一马平川</text>
            </up-collapse-item>
            <up-collapse-item
                    title="组件全面"
            >
                <text class="u-collapse-content">众多组件覆盖开发过程的各个需求,组件功能丰富,多端兼容。让您快速集成,开箱即用</text>
            </up-collapse-item>
            <up-collapse-item
                    title="众多利器"
            >
                <text class="u-collapse-content">众多的贴心小工具,是您开发过程中召之即来的利器,让您飞镖在手,百步穿杨</text>
            </up-collapse-item>
        </up-collapse>
    </view>
</template>

<style>
.u-page {
  padding: 0;
}

.u-page__item__title {
  color: var(--u-tips-color);
  background-color: var(--u-bg-color);
  padding: 15px;
  font-size: 15px;
}

.u-page__item__title__slot-title {
  color: var(--u-primary);
  font-size: 14px;
}

.u-collapse-content {
  color: var(--u-tips-color);
  font-size: 14px;
}
</style>

自定义标题和内容

  • 通过设置slot来自定义标题和内容
html
<template>
    <view class="u-page__item">
        <text class="u-page__item__title">自定义标题和内容</text>
        <up-collapse
                accordion
        >
            <up-collapse-item
            >
                <text slot="title" class="u-page__item__title__slot-title">文档指南</text>
                <text class="u-collapse-content">涵盖uniapp各个方面,给开发者方向指导和设计理念,让您茅塞顿开,一马平川</text>
            </up-collapse-item>
            <up-collapse-item
                    title="组件全面"
            >
                <up-icon name="tags-fill" size="20" slot="icon"></up-icon>
                <text class="u-collapse-content">众多组件覆盖开发过程的各个需求,组件功能丰富,多端兼容。让您快速集成,开箱即用</text>
            </up-collapse-item>
            <up-collapse-item
                    title="众多利器"
            >
                <text slot="value" class="u-page__item__title__slot-title">自定义内容</text>
                <text class="u-collapse-content">众多的贴心小工具,是您开发过程中召之即来的利器,让您飞镖在手,百步穿杨</text>
            </up-collapse-item>
        </up-collapse>
    </view>
</template>

<style>
.u-page {
  padding: 0;
}

.u-page__item__title {
  color: var(--u-tips-color);
  background-color: var(--u-bg-color);
  padding: 15px;
  font-size: 15px;
}

.u-page__item__title__slot-title {
  color: var(--u-primary);
  font-size: 14px;
}

.u-collapse-content {
  color: var(--u-tips-color);
  font-size: 14px;
}
</style>

此页面源代码地址

页面源码地址


 github  gitee

API

Collapse Props

参数说明类型默认值可选值
value当前展开面板的name,非手风琴模式:[<String | Number>],手风琴模式:String | NumberString | Number | Array--
accordion是否手风琴模式Booleanfalsetrue
border是否显示外边框Booleantruefalse

Collapse Item Props

参数说明类型默认值可选值
title面板标题String--
value标题右侧内容String--
label标题下方的描述信息String--
disabled面板是否可以打开或收起Booleanfalsetrue
isLink是否展示右侧箭头并开启点击反馈Booleantruefalse
clickable是否开启点击反馈Booleantruefalse
border是否显示内边框Booleantruefalse
align标题的对齐方式Stringleft-
name唯一标识符,如不设置,默认用当前collapse-item的索引值String | Number--
icon标题左侧图片,可为绝对路径的图片或内置图标String--
duration面板展开收起的过渡时间,单位msNumber300-

Collapse Event

注意:请在<up-collapse></up-collapse>上监听此事件

事件名说明回调参数
change当前激活面板展开/关闭时触发(如果是手风琴模式,参数activeNames类型为String,否则为Array)activeNames: String | Array
open当前激活面板展开时触发(如果是手风琴模式,参数activeNames类型为String,否则为Array)activeNames: String | Array
close当前激活面板关闭时触发(如果是手风琴模式,参数activeNames类型为String,否则为Array)activeNames: String | Array

Collapse Methods

注意:此方法需要通过ref调用

方法说明
init重新初始化内部高度计算,用于异步获取内容的情形,请结合this.$nextTick()使用

Slot

微信小程序不支持slot写法

名称说明
-主体部分的内容
title标题内容
iconicon
value右侧value
right-icon右侧icon

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发