这次给大家带来vue实现点击展开点击收起功能实现,vue实现点击展开点击收起功能实现的注意事项有哪些,下面就是实战案例,一起来看一下。
首先定义一下data里面的数据:
data () {
return {
toLearnList:[
'html','css','javascript','java','php' //进行显示的数据
],
showAll:false, //标记数据是否需要完全显示的属性
}
}使用computed对data进行处理:
computed:{
showList:function(){
if(this.showAll == false){ //当数据不需要完全显示的时候
var showList = []; //定义一个空数组
if(this.toLearnList.length > 3){ //这里我们先显示前三个
for(var i=0;i<3;i++){
showList.push(this.toLearnList[i])
}
}else{
showList = this.toLearnList
}
return showList; //返回当前数组
}else{
return this.toLearnList;
}
},
word:function(){
if(this.showAll == false){ //对文字进行处理
return '点击展开'
}else{
return '点击收起'
}
}
}template:循环的时候直接用showList进行操作,显示收起的事件直接用showAll = !showAll 进行控制,改变这个值的真假
<template>
<p class="hello">
<p v-for='item in showList'>{{item}}</p>
<p @click="showAll = !showAll" class="show-more">{{word}}</p>
</p>
</template>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是vue实现点击展开点击收起功能实现的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号