uniapp 内容展开组件

uni-collapse折叠面板并不符合需求,需要自己写一个。

效果展示:

代码: (vue3版本)

javascript 复制代码
<template>
  <view class="collapse-view">
    <view class="collapse-content">
      <swiper
        :autoplay="false"
        :circular="true"
        :indicator-dots="false"
        :style="{
          width: '100%',
          height: calcHeight(),
        }"
        class="collapse-swiper"
        @change="changeSwp"
      >
        内容区域
      </swiper>
      <view class="mode-change" @click="changeMode">
        <!-- 上下展开的小图标-->

        <uni-icons
          v-if="isCollapse"
          type="bottom"
          size="18"
          color="#165dff"
        ></uni-icons>
        <uni-icons v-else type="top" size="18" color="#165dff"></uni-icons>
      </view>
    </view>
  </view>
</template>

<script setup>
import {ref,reactive} from 'vue'
let isCollapse =ref(true) //是否展开控件
// 计算组件内容区域的高度
const calcHeight = () =>{
  //默认高度
  let h = "70rpx";
  if (!isCollapse.value) {
    //展开后高度
    h = 190 + "rpx";
  }
  return h;
}
//切换展开与否
const changeMode =()=>{
  isCollapse.value =!isCollapse.value
}
</script>
<style lang="scss" scoped>
.collapse-view {
  width: 100%;
  height: auto;
  background-color: #fff;
  margin-top: 20rpx;

  swiper {
    width: 100%;
    height: 60upx;
  }
  .collapse-content {
    padding-bottom: 26rpx;
    border-bottom: 1upx solid #f7f7f7;
    border-bottom-left-radius: 37upx;
    border-bottom-right-radius: 37upx;
  }
  .collapse-swiper {
    min-height: 70upx;
    transition: height ease-out 0.3s;
  }
  .mode-change {
    display: flex;
    justify-content: center;
    margin-top: 10upx;
    margin-bottom: 22upx;

    :deep(.uni-icons) {
      position: absolute;
    }
  }
}
</style>

vue2版本的 逻辑片段

javascript 复制代码
<script>
export default {
  props: {},

  computed: {
//结构部分直接写 calcHeight来调用。不要()
    calcHeight() {
      //默认高度
      let h = "70rpx";
      if (!this.isCollapse) {
       //展开后高度
        h = 190 + "rpx";
      }
      return h;
    },
  },
  data() {
    return {
      isCollapse: true, //展开与折叠控件
    };
  },
  methods: {
    changeMode() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
    
</script>
相关推荐
猫头_几秒前
AI 流式传输工程指南:有了 EventSource 为何还要 Fetch?
javascript·http·llm
hunterandroid11 分钟前
Paging 3 RemoteMediator 实战:构建离线优先的分页列表
android·前端
Underwood_1714 分钟前
星级评价——了解useState
前端
hunterandroid18 分钟前
[鸿蒙从零到一] ArkUI 组件化实战:构建可复用、可组合的自定义组件
前端·华为·架构
一只公羊20 分钟前
iPhone摄像头 在开发/调试过程中强行停止 App,导致 `AVCaptureSession` 没有被正常释放
前端
良木林1 小时前
滑动窗口 - LeetCode hot 100
javascript·算法·leetcode·双指针·滑动窗口
华玥作者1 小时前
uniapp 万条数据不卡顿:我写了个虚拟列表组件 hy-list,原生支持瀑布流
数据结构·uni-app·list·vue3
浮江雾1 小时前
Flutter第十节-----Flutter布局与组件全解析
android·开发语言·前端·学习·flutter·入门
这是个栗子1 小时前
uni-app 微信小程序开发:常用函数总结(一)
微信小程序·小程序·uni-app·getcurrentpages