【uniapp手写组件】折叠面板组

折叠面板组件代码:

template:

<template>
  <div>
    <div class="panel" v-for="(item, index) in list">
      <div class="panel-header" @click="togglePanel(index)">
        <span>{{ item.title }}</span>
        <i :class="item.show ? 'iconfont icon-xiangxia' : 'iconfont icon-xiangyou'"></i>
      </div>
      <div class="panel-content" v-show="item.show">
        {{ item.content }}
      </div>
    </div>
  </div>
</template>

script:

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true
    }
  },
  methods: {
    togglePanel(index) {
      this.list[index].show = !this.list[index].show;
    }
  }
}
</script>

style:

<style scoped>
.panel {
  margin: 10px auto;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #f5f5f5;
  padding: 10px;
  cursor: pointer;
}

.panel-content {
  padding: 10px;
  background-color: #fff;
  overflow: hidden;
  transition: height 0.3s ease-in-out;
}
</style>

使用方法:

<template>
  <div>
    <fold-panel :list="list"></fold-panel>
  </div>
</template>
<script>
import FoldPanel from '@/components/FoldPanel.vue'

export default {
  components: {
    FoldPanel
  },
  data() {
    return {
      list: [
        {
          title: '标题1',
          content: '内容1',
          show: false
        },
        {
          title: '标题2',
          content: '内容2',
          show: false
        }
      ]
    }
  }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值