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.效果图

vue2.0 自定义 折叠列表(Accordion)组件的更多相关文章

  1. vue2.0 自定义 提示框(Toast)组件

    1.自定义 提示框 组件 src / components / Toast / index.js /** * 自定义 提示框( Toast )组件 */ var Toast = {}; var sho ...

  2. [js高手之路]Vue2.0基于vue-cli+webpack父子组件通信教程

    在git命令行下,执行以下命令完成环境的搭建: 1,npm install --global vue-cli  安装vue命令行工具 2,vue init webpack vue-demo   使用v ...

  3. 采用Vue2.0开发的分页js组件

    2017-11-17 19:14:23 基于jQuery的分页插件相信大家伙已经都用过很多了,今天分享一下基于Vue2.0的分页插件pagination.js 由于项目需求,要求使用 Vue2.0 开 ...

  4. CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法

    因业务需求,要在 vue2.0 的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用.因 CKEditor5 文档比较少,此处记录下引用和一些基本用法. CKEdit ...

  5. vue2.0项目 calendar.js(日历组件封装)

    最近一直闲来无事,便寻思着做一下自己的个人项目,也想说能使用现在比较流行的一些mvvm框架来做,于是就选用了这样的一个技术栈vue2.0+vue-router+vuex+webpack来做,做得也是多 ...

  6. vue2.0自定义指令

    前面一片文章说了vue2.0过滤器,其实自定义指令跟过滤器非常相似,单就定义方式而言,其与过滤器完全一致,分为局部指令,和全局指令.不过就是filter改为directive的区别. 过滤器一般用于对 ...

  7. vue2.0 自定义 图片上传(UpLoader)组件

    1.自定义组件 UpLoader.vue <!-- 上传图片 组件 --> <template> <div class="vue-uploader"& ...

  8. vue2.0 自定义 弹窗(MessageBox)组件

    组件模板 src/components/MessageBox/index.vue <!-- 自定义 MessageBox 组件 --> <template> <div c ...

  9. vue2.0 自定义 饼状图 (Echarts)组件

    1.自定义  图表  组件 Echarts.vue <!-- 自定义 echart 组件 --> <template> <div> <!-- echart表格 ...

随机推荐

  1. linuxlinux0.11源码学习——bootsect.s学习

    由于一直想写一个自己的操作系统,网上推荐了<linux内核完全注释>.自学了一个星期,感觉这本书还是很好的,同时写下关于内核代码的理解,如果有什么不对的对方,欢迎大家一起来交流. 在内核引 ...

  2. [git 学习篇] git commit原理 --实践体会

    1 现对readme.txt作出修改,增加一行内容: Git has a mutable index called stage. Git is a distributed version contro ...

  3. 指定特殊的安装目录用configure进行配置

    linux - Make install, but not to default directories? - Stack Overflow I want to run 'make install' ...

  4. javascript学习笔记 - 引用类型 RegExp

    四 RegExp 格式: var expression = / pattern / flags; 1.flags 为标志.分别为g.i.m. g:表示全局模式.即模式将匹配所有的字符串,而不是在发现第 ...

  5. No entity found for query异常

    错误为getSingleResult();获取值时获取不到报异常. getSingleResult的源码有一句: @throws EntityNotFoundException if there is ...

  6. bootstrap 中dropmenu不起作用

    今天在使用bootstrap发现dropmenu一直不起作用,代码是从官网拷贝过来. 网上查找可以用的页面进行一点点的去除分析,发现竟然是顺序反了导致的. 在使用dropmenu时需要引入jquery ...

  7. P1438 无聊的数列 (线段树)

    题目链接 Solution 直接维护一个差分的线段树就好了. 其中线段树的节点代表 \(r\) 比 \(l\) 多多少. Code #include<bits/stdc++.h> #def ...

  8. vue.js源码学习分享(九)

    /* */ var arrayKeys = Object.getOwnPropertyNames(arrayMethods);//获取arrayMethods的属性名称 /** * By defaul ...

  9. 美图秀秀web开发文档

    Xiuxiu 组件 import React, { Component } from 'react'; class XiuXiu extends Component { componentDidMou ...

  10. Network | DHCP

    动态主机设置协议(Dynamic Host Configuration Protocol, DHCP)是一个局域网的网络协议,使用UDP协议工作,主要有两个用途: 给内部网络或网络服务供应商自动分配I ...