Vue中用v-for循环出来的数据,如何单独控制隐藏显示

搜了好多,没得到想要的答案。

终于用自己的方法解决了问题。

上代码:

html部分

              <dl class="cc" v-for="(item, index) in courseList" :key="index">
                <dt class="active" @click="showAndHide">
                  <h5>{{index + 1}} | {{item.name}}</h5>
                  <span class="arrow"></span>
                </dt>
                <video-list :class_id="classId" :course_id="item.course_id"></video-list>
              </dl>

方法部分

    showAndHide (event) {
      let _el = event.currentTarget
      if (_el.getAttribute('class') === 'active') {
        _el.setAttribute('class', '')
      } else {
        _el.setAttribute('class', 'active')
      }
    }

达到效果,可以单独控制显示和隐藏

 

posted @ 2019-10-11 00:02  鳳舞九天  阅读(12904)  评论(3编辑  收藏  举报