vue v-for循环

vue v-for循环中通过一个变量控制不同的下拉框

默认是在这里插入21图片描述
默认是全部展开,当点击每个表格的下拉图标,就会显示或隐藏,刚开始做的时候就通过一个变量进行控制,导致点击一个下拉图标就会控制所有有的表格下拉,所以应该是给每个表格对应的集合中加一条属性来判断当前v-for循环中的index值是否为true或false

 <template v-for="(item,index) in (this.model)">
        <div :key="index" class="box-body">
          <div class=" info-box-mag">
            <div class="seachTit">
              {{ $t("views.allApplication_list.update_time") }}:
              {{ item.dtAction|formatDateTime }}
              <div class="pull-right mt5">
                <i
                  :class="[searchFormShow02[index]? 'fas show-form fa-chevron-up pull-right'
                    :'fas show-form fa-chevron-down pull-right']"
                  @click="changeShow(index)"
                />
              </div>
            </div>
            <transition name="slide-fade">
              <div v-show="searchFormShow02[index]" :key="index">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
                  <tbody>
                    <tr>
                      <th class="p_th">{{ $t("views.allApplication_list.application_jinglu") }}</th>
                      <td>{{ item.txtApprovalPath }}</td>
                    </tr>
                    <tr>
                      <th class="p_th">{{ $t("views.allApplication_list.update_user") }}</th>
                      <td>{{ item.nmActionUser }}</td>
                    </tr>
                    <tr>
                      <th class="p_th">{{ $t("views.allApplication_list.update_text") }}</th>
                      <td v-if="item.typeAction==1">{{ $t("views.allApplication_list.saveButton") }}</td>
                      <td v-else-if="item.typeAction==2">{{ $t("views.allApplication_list.updateButton") }}</td>
                      <td v-else-if="item.typeAction==3">{{ $t("views.allApplication_list.application_confirm") }}</td>
                      <td v-else-if="item.typeAction==4">{{ $t("views.allApplication.typeStatus4") }}</td>
                      <td v-else-if="item.typeAction==5">{{ $t("views.allApplication.typeStatus5") }}</td>
                      <td v-else-if="item.typeAction==6">{{ $t("views.allApplication.typeStatus6") }}</td>
                      <td v-else>{{ $t("views.allApplication.typeStatus7") }}</td>
                    </tr>
                  </tbody>
                </table>

              </div>
            </transition>
          </div>
        </div>

      </template>

存储当前index下的true/false值
data() {
    return {
      searchFormShow02: {
        "0111": ["true"]
      }

    };
  },
 methods: {
    init(val) {
      for (let i = 0; i < val.length; i++) {
        this.$set(this.searchFormShow02, i, true);
      }
      console.log(this.searchFormShow02);
    },
    changeShow(index) {
      if (this.searchFormShow02[index] === true) {
        this.$set(this.searchFormShow02, index, false);
      } else {
        this.$set(this.searchFormShow02, index, true);
      }

      // console.log(this.searchFormShow02);
    }
  }

先获取到后端传来的数组,然后循环遍历数组长度,新建一个searchFormShow02变量,存储index值,全部赋值为true
在这里插入图片描述
然后点击每一行的下拉图标,进入到changeShow(index)方法,改变searchFormShow02[index]的属性,通过this.$set改变对象的值,然后渲染页面

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值