今天小编大家分享一篇vue2.0 可折叠列表 v-for循环展示的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
先上一张效果图:
以前用angularjs操作基本上都是要取到每个列表的id再循环判断是不是当前点击的列表来显示折叠。
今天在这个项目 https://github.com/IFmiss/vue-music 上看到操作很简单,并没有如此复杂。赶紧记录一下:
折叠列表单独做一个组件,图标是用的iconfont中生成的css链接:myMusicSheetList.vue
<div class="sheet-list"> <div class="sheet-header"> <i class="icon iconfont icon-enter"></i><span class="sheet-header-span">{{data_item.name}} <span> ({{data_item.num}}) </span></span><i class="sheet-header-i icon iconfont icon-setup"></i></div><div class="sheet-content"> <div class="sheet-content-image"> </div><div class="sheet-content-middle"> <p>{{i.details_name}}</p><p style="margin-top: 10px;font-size: 14px;color: #666">{{i.details_num}}首歌曲</p></div><i class="icon iconfont icon-switch"></i></div></div>
.sheet-list{ clear: both; } .sheet-header{ height: 30px;background: #e5e5e5;position: relative; } .sheet-header i:nth-child(1){ line-height: 30px;position:absolute; left:10px; color:#666; transition:all 0.5s; } .s<div style="color:transparent">本文来源gaodai.ma#com搞##代!^码网(</div>heet-header-i{ line-height: 30px;position: absolute;right: 10px; } .sheet-header-span{ left: 40px;font-size: 14px;position:absolute;line-height: 30px; } .sheet-content{ position: relative;width: 100%;display: flex; } .sheet-content i{ font-size: 26px;position: absolute;right: 10px;top: 50%;transform:translate(0,-50%); } .sheet-content-image{ width: 60px;float: left;text-align: center; } .sheet-content-middle{ position: relative;width: 100%;border-bottom: 1px solid #e5e5e5;padding-bottom: 10px;margin-top: 10px;margin-left: 10px; } .sheet-content-middle p{ font-size: 16px;width: 70%;color: #666;text-overflow:ellipsis;white-space: nowrap;overflow:hidden; }
主页面调用组件:home.vue
<div class="home"> </div>
如果不能运行请检查import 路径是否正确。
以上就是vue2.0 可折叠列表 v-for循环展示的实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!