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>
相关推荐
步行cgn1 分钟前
为什么既要 web.xml 又要 springmvc.xml?能不能只配一个?
xml·前端·hive
风骏时光牛马8 分钟前
大模型综合能力评测:多维度性能与对齐效果对比
前端
winfredzhang14 分钟前
从零手写一个毛玻璃风格的页面搭建台:单文件 HTML 实现组件放置、面板磁吸与图层管理
前端·html
葡萄城技术团队9 小时前
1000 人协同压测的环境瓶颈排查:CPU 争用与 Wi\-Fi
前端
excel10 小时前
Marked 与 Markdown 有什么区别?该怎么选?
前端
Da Da 泓11 小时前
五子棋 Web 端测试用例报告
前端·网络·websocket·网络协议·测试用例·项目
zxcvb15311 小时前
远程查看本地文档:一条轻量 Web 文件服务的工程化链路
前端·远程查看文档
niucloud-admin11 小时前
NIUCLOUD PHP SAAS上门家政使用文档:城市管理
java·前端·php
程序员大阳12 小时前
副队长JavaScript教程(50)-DOM:网页开发的起点
javascript·dom·es·节点·概念·document·关系
北岛贰12 小时前
啵啵音乐迎来全新升级!
前端