v-for循环出的列表如何实现每一项单独展开收起

可以同时展开多个各个互不影响

data中声明要循环的数据、当前的下标数组类型(array)
思路:判断当年下标是否在数组下标中来控制展开收起,不存在就将该下标加入数组,再点击一次这个下标则删去,数组中无该下标就显示收起。

<div class="content" v-for="(t,index) in List" :key="t.id">
   <div class="desc">
      <span class="btn" 
          :style="{'color': (thisIndex.indexOf (index)!=-1? '#0195ff':'#999999')}" 
          @click="show(index)">
        {{thisIndex.indexOf (index)!=-1 ? '收起' : '展开'}}
      </span>
      <i :class="thisIndex.indexOf (index) != -1 ? 'el-icon-d-arrow-left' : 'el-icon-d-arrow-right'" 
         :style="{'color': (thisIndex.indexOf (index)!=-1? '#0195ff':'#999999')}"></i>
      <div class="content" v-show="thisIndex.indexOf (index)!=-1">{{t.content}}</div>
   </div>
</div>
data() {
    return{
     List:[],
      thisIndex: []   如果想要初始化时就展开 就将下标放在thisIndex里面
    }  
  },
  methods: {
    show(index) {
      if(this.thisIndex.indexOf(index) == -1){
        this.thisIndex.push(index)
      }else{
        this.thisIndex = this.thisIndex.filter(item => item != index)
      }
    }
  }

[vue]v-for循环出的列表如何实现每一项单独展开收起_vue循环展开-CSDN博客

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 19:20:05       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 19:20:05       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 19:20:05       45 阅读
  4. Python语言-面向对象

    2024-07-20 19:20:05       55 阅读

热门阅读

  1. 在Spring Boot中实现文件上传与管理

    2024-07-20 19:20:05       17 阅读
  2. 掌握Perl中的异常处理:自定义错误管理的艺术

    2024-07-20 19:20:05       15 阅读
  3. Emacs

    2024-07-20 19:20:05       20 阅读
  4. 可再生能源工厂系统 (REPS) - 项目源码

    2024-07-20 19:20:05       17 阅读
  5. Python __init__与__new__的区别

    2024-07-20 19:20:05       13 阅读
  6. 深入探索Perl中的函数定义与调用机制

    2024-07-20 19:20:05       19 阅读
  7. lua语法思维导图

    2024-07-20 19:20:05       11 阅读
  8. Perl脚本的魔法:打造自定义文件系统视图

    2024-07-20 19:20:05       19 阅读