1.自定义  折叠列表

Accordion.vue

(1)sass  版本

<!-- 折叠列表 组件 -->
<template>
<nav :class="$style.accWrapper">
<div :class="$style.accTitle" @click="toggleList">
<span>{{ title.area }}</span>
<span>当前人数:{{ title.num }}人</span>
<span>总人数:{{ title.sum }}人</span>
<img
src="../assets/img/arrow_right.png"
alt="chevron"
:class="[{ [$style.open_menu]: isDisplay, [$style.close_menu]: !isDisplay }, $style.accChevron]"
/>
</div>
<ul :class="[{ [$style.maxHeight]: isDisplay }, $style.accList]">
<li :class="$style.accListItem" v-for="item in list">
<span>{{ item.area }}</span>
<span>当前人数:{{ item.num }}人</span>
<span>总人数:{{ item.sum }}人</span>
</li>
</ul>
</nav>
</template> <script>
export default {
data () {
return {
isDisplay: false
}
},
props: {
title: {
type: Object,
default(){
return {}
}
},
list: {
type: Array,
required: true
}
},
methods: {
toggleList () {
this.isDisplay = !this.isDisplay
}
}
}
</script> <style lang="scss" module>
.accWrapper {
display:flex;
flex-direction: column;
}
.accTitle {
display: flex;
justify-content: space-between;
align-items: baseline;
height: 50px;
line-height: 50px;
font-size: 16px;
background: #eee;
text-indent: 1em;
cursor: pointer;
}
.accChevron {
width: 20px;
margin-right: 15px;
}
.accList{
list-style: none;
padding: 0;
margin: 0;
font-size: 16px;
overflow: hidden;
max-height: 0;
transition: max-height .5s ease-out;
}
.accList.maxHeight {
max-height: 500px;
transition: max-height .5s ease-in;
}
.accListItem {
background-image: url(../assets/img/arrow_right.png);
background-repeat: no-repeat;
background-size: 20px 20px;
background-position: 95% 50%;
display: flex;
// justify-content: space-between;
align-items: baseline;
height: 50px;
line-height: 50px;
font-size: 16px;
text-indent: 1em;
cursor: pointer;
}
/* chevron animation */
@keyframes open-menu {
to {
transform: rotate(90deg);
}
}
@keyframes close-menu {
from {
transform: rotate(90deg);
}
to {
transform: rotate(0deg);
}
}
.open_menu {
animation: open-menu 0.4s ease-out forwards;
}
.close_menu {
animation: close-menu 0.4s ease-out forwards;
}
</style>

(2)less  版本

<!-- 折叠列表 组件 -->
<template>
<nav class="accWrapper">
<div class="accTitle" @click="toggleList">
<span>{{ title.area }}</span>
<span>当前人数:{{ title.num }}人</span>
<span>总人数:{{ title.sum }}人</span>
<img
src="../assets/img/arrow_right.png"
alt="chevron"
:class="['accChevron', { 'open_menu': isDisplay, 'close_menu': !isDisplay }]"
/>
</div>
<ul :class="['accList', { 'maxHeight': isDisplay }]">
<li class="accListItem" v-for="item in list">
<span>{{ item.area }}</span>
<span>当前人数:{{ item.num }}人</span>
<span>总人数:{{ item.sum }}人</span>
</li>
</ul>
</nav>
</template> <script>
export default {
data () {
return {
isDisplay: false
}
},
props: {
title: {
type: Object,
default(){
return {}
}
},
list: {
type: Array,
required: true
}
},
methods: {
toggleList () {
this.isDisplay = !this.isDisplay
}
}
}
</script> <style lang="less" scoped>
.accWrapper {
display:flex;
flex-direction: column;
}
.accTitle {
display: flex;
justify-content: space-between;
align-items: baseline;
height: 50px;
line-height: 50px;
font-size: 16px;
background: #eee;
text-indent: 1em;
cursor: pointer;
}
.accChevron {
width: 20px;
margin-right: 15px;
}
.accList{
list-style: none;
padding: 0;
margin: 0;
font-size: 16px;
overflow: hidden;
max-height: 0;
transition: max-height .5s ease-out;
}
.accList.maxHeight {
max-height: 500px;
transition: max-height .5s ease-in;
}
.accListItem {
background-image: url(../assets/img/arrow_right.png);
background-repeat: no-repeat;
background-size: 20px 20px;
background-position: 95% 50%;
display: flex;
// justify-content: space-between;
align-items: baseline;
height: 50px;
line-height: 50px;
font-size: 16px;
text-indent: 1em;
cursor: pointer;
}
/* chevron animation */
@keyframes open-menu {
to {
transform: rotate(90deg);
}
}
@keyframes close-menu {
from {
transform: rotate(90deg);
}
to {
transform: rotate(0deg);
}
}
.open_menu {
animation: open-menu 0.4s ease-out forwards;
}
.close_menu {
animation: close-menu 0.4s ease-out forwards;
}
</style>

  

2.页面调用

Fold.vue

<!-- 折叠列表 -->
<template>
<div>
<!-- 标题栏 -->
<mt-header title="折叠列表">
<router-link to="/" slot="left">
<mt-button icon="back">返回</mt-button>
</router-link>
</mt-header>
<!-- 列表 -->
<accordion
v-for="(item,index) in dataList"
:key="item.id"
:title="item"
:list="item.child">
</accordion>
</div>
</template> <script>
import Accordion from '../components/Accordion' export default {
name: 'Fold',
components: {
Accordion,
},
data(){
return {
dataList:[
{"area":"深圳","num":"10","sum":"30","child":[
{"area":"罗湖","num":"20","sum":"20"},
{"area":"福田","num":"20","sum":"20"},
{"area":"南山","num":"20","sum":"20"}
]},
{"area":"广州","num":"10","sum":"30","child":[
{"area":"白云","num":"20","sum":"20"},
{"area":"福田","num":"20","sum":"20"},
{"area":"南山","num":"20","sum":"20"}
]}
]
}
}
}
</script> <style lang="scss" scoped>
//
</style>

3.效果图

最新文章

  1. linux 守护程序小记(指定进程不存在则启动 )
  2. iOS开发——项目篇—高仿百思不得姐 05——发布界面、发表文字界面、重识 bounds、frame、scrollView
  3. ucenter 显示通信成功的条件
  4. 定时每天执行前一天的数据导入oracle
  5. java中封装
  6. uvalive 7331 Hovering Hornet 半平面交+概率期望
  7. PHP实现动态生成饼状图 (转载)
  8. application&#160;windows&#160;are&#160;expected&#160;to&#160;have&#160;a&#160;root&#160;view&#160;controller错误
  9. Unity 游戏框架搭建 (二) 单例的模板
  10. python学习1:程序元素和基本使用方法(跟随mooc学习)
  11. pandas的apply操作
  12. PE知识复习之PE的RVA与FOA的转换
  13. 【AO笔记】Addins的Toolbar 添加一条分割线
  14. HDU/HDOJ 2087 剪花布条
  15. HDU5399-多校-模拟
  16. spark run using IDE / Maven
  17. js控制手机端字体大小rem
  18. Maven内置属性及使用
  19. Uncaught TypeError: timeout.close is not a function. when try to use clearInterval
  20. Spark2.x AFTSurvivalRegression算法

热门文章

  1. HTTP LVS
  2. JS进行人民币大小写转换
  3. not exists、left join/is null、not in 行为
  4. 【Luogu】P1430序列取数(DP)
  5. POJ——1195Mobile phones(二维树状数组点修改矩阵查询)
  6. 如何用1个小时了解JSON
  7. 面试题之redis的过期时间原理
  8. [暑假集训--数位dp]LightOj1205 Palindromic Numbers
  9. hdu 3625 Examining the Rooms 轮换斯特林数
  10. 应用express mockjs模拟前端json数据接口