侧边栏手风琴效果

html

<ul>
  <li :class="{active:item.show}" @click="changeli(index, item)" v-for="(item,index) in headerData" :key='index'>
    {{item.name}}{{item.show}}
    <ul v-show="item.show">
      <li v-for="(a,index) in item.list" @click.stop="doThis(index)" :key='index'>{{a}}        
      </li>
    </ul>
  </li>
</ul>

js

changeli (index, item) {
  // 循环所有列表,去掉展开的item
  this.headerData.forEach(i => {
    if (i.show !== this.headerData[index].show) {
      i.show = false
    }
  })
  item.show = !item.show
},
doThis (index) {
  alert(index)
}
    原文作者:流年朝朝
    原文地址: https://segmentfault.com/a/1190000016950804
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞