vue2.0 可折叠列表 v-for循环展示的实例
作者:qq_27717857 发布时间:2024-04-28 09:32:22
标签:vue2.0,列表,v-for,循环
先上一张效果图:
以前用angularjs操作基本上都是要取到每个列表的id再循环判断是不是当前点击的列表来显示折叠。
今天在这个项目 https://github.com/IFmiss/vue-music 上看到操作很简单,并没有如此复杂。赶紧记录一下:
折叠列表单独做一个组件,图标是用的iconfont中生成的css链接:myMusicSheetList.vue
<template>
<div class="sheet-list">
<div class="sheet-header" @click="toggleSheet">
<i class="icon iconfont icon-enter" ref="toggleicon"></i>
<span class="sheet-header-span">{{data_item.name}} <span> ({{data_item.num}}) </span></span>
<i class="sheet-header-i icon iconfont icon-setup" @click.stop="showSheetMenu(data_item.name)"></i>
</div>
<div v-if="showSheets" class="sheet-content" v-for="i in data_item.details">
<div class="sheet-content-image">
<img :src="i.details_image" width="50" height="50" style="padding: 5px;overflow: hidden">
</div>
<div class="sheet-content-middle">
<p style="">{{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" @click.stop="showSheetMenu()"></i>
</div>
</div>
</template>
<script>export default { components:{}, props: { item:{ type:Object } }, data(){ return{ showSheets:false, data_item:{} } }, methods:{//向右的小图标动画 toggleSheet:function(index){ console.log(this.$refs); this.$refs.toggleicon.style.transform = !this.showSheets ? 'rotate(90deg)' : 'rotate(0)'this.showSheets = !this.showSheets }, showSheetMenu:function(){ alert(1111); } }, created(){ this.data_item = this.item; },}</script>
<style scoped>
.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;
}
.sheet-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;
}
</style>
主页面调用组件:home.vue
<template>
<div class="home">
<sheet-list v-for="(item,index) in sheetList" :item="item"></sheet-list>
</div>
</template>
<script>
import myMusicSheetList from './../../components/myMusicSheetList.vue'
export default {
components:{'sheet-list':myMusicSheetList},
data () {
return {
sheetList:[{
id:1,
name:'我创建的歌单',
num:2,
details:[{
details_id:1,
details_name:'我喜欢的音乐',
details_num:30,
details_image:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1521191038714&di=117b8f1d83605767e8a7faf01cb9be9b&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2F8435e5dde71190efc4376916c41b9d16fcfa602f.jpg'
},{
details_id:2,
details_name:'在欧洲田园般的乡村上骑单车',
details_num:15,
details_image:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1521190642670&di=67822ec270160c1fb21e67d49e95a97f&imgtype=0&src=http%3A%2F%2Fpic30.nipic.com%2F20130615%2F2861027_140302450156_2.jpg'
}]
},{
id:2,
name:'我收藏的歌单',
num:2,
details:[{
details_id:1,
details_name:'这应该是你比较喜欢听的歌曲了',
details_num:10,
details_image:'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3679981803,1758706610&fm=27&gp=0.jpg'
},{
details_id:2,
details_name:'欧美风格的音乐,安静的听',
details_num:2,
details_image:'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2406805917,4090912031&fm=27&gp=0.jpg'
}]
}]
}
},
methods: {
},
mounted:function(){
}
}
</script>
<style scoped>
</style>
如果不能运行请检查import 路径是否正确。
来源:https://blog.csdn.net/qq_27717857/article/details/79582097


猜你喜欢
- 无论是在小得可怜的免费数据库空间或是大型电子商务网站,合理的设计表结构、充分利用空间是十分必要的。这就要求我们对数据库系统的常用数据类型有充
- Oracle不像SQLServer那样在存储过程中用Select就可以返回结果集,而是通过Out型的参数进行结果集返回的。实际上是利用REF
- Session StaticObjects 集合StaticObjects 集合包含 Session 对象范围中用 <OBJECT&g
- 在之前一篇文章中我介绍了通过定义Response宏的方式来实现动态改变模板文件路径以实现主题功能: laravel实现模板主题功能,但后来我
- 在开发过程中经常碰到在本地环境无法完成联调测试的情况,必须到统一的联机环境对接其他系统测试。往往是出现了BUG难以查找数据记录及时定位到错误
- 在python中调用fortran代码,要用到f2py这个程序。它的项目主页在此。现在该项目已经合并到numpy中了,先安装python再装
- 在用jupyter notebook写python代码的过程中会产生很多变量,而关闭后或者restart jupyter kernel后所有
- 在ASP.NET2.0通过SMTP的验证发送EMAIL ,代码如下:’Create a new MailMes
- 刚接触 Go 语言时,就听说有一个叫rune的数据类型,即使查阅过一些资料,对它的理解依旧比较模糊,加之对陌生事物的天然排斥,在之后很长一段
- 本文中的示例主要是解决在函数间不能传递多个(32个以上)参数的问题,解题的具体思路就是采用记录类型作为函数的输入和返回值,所以我们需要先定义
- 在Python数据可视化中,seaborn较好的提供了图形的一些可视化功效。seaborn官方文档见链接:http://seaborn.py
- 本文实例为大家分享了python实现最速下降法的具体代码,供大家参考,具体内容如下代码:from sympy import *import
- 引言:在机器学习还有深度学习中,经常会用到这几个函数,为了便于以后熟练使用,现在对这几个函数进行总结。(一)np.random.rand()
- /* 建立数据表 */ create table td_base_data( id int(10) not null auto_increm
- URL重定向行为路由的尾部加不加斜杠不一样的,比如:from flask import Flaskapp = Flask(__name__)
- 1、将一个字典输入:该字典必须满足:value是一个list类型的元素,且每一个key对应的value长度都相同:(以该字典的key为col
- 本文介绍了python selenium UI自动化解决验证码的4种方法,分享给大家,具体如下:测试环境windows7+firefox50
- 昨天我的电影网站在生成内容静态页面的时候出了问题,提示下标越界,以前从来没有遇到过的,所以根本不知道是什么东西,于是就到处在网上找答案,但是
- Readme:blog address:摘要:编写登录接口输入用户名、密码认证成功后显示欢迎信息输错3次后锁定关键词:循环;判断;外部数据读
- 在Golang中,如何将一个结构体转成map? 本文介绍两种方法。第一种是是使用json包解析解码编码。第二种是使用反射,使用反射的效率比较