vue2.0 自定义 折叠列表(Accordion)组件
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)组件的更多相关文章
- vue2.0 自定义 提示框(Toast)组件
1.自定义 提示框 组件 src / components / Toast / index.js /** * 自定义 提示框( Toast )组件 */ var Toast = {}; var sho ...
- [js高手之路]Vue2.0基于vue-cli+webpack父子组件通信教程
在git命令行下,执行以下命令完成环境的搭建: 1,npm install --global vue-cli 安装vue命令行工具 2,vue init webpack vue-demo 使用v ...
- 采用Vue2.0开发的分页js组件
2017-11-17 19:14:23 基于jQuery的分页插件相信大家伙已经都用过很多了,今天分享一下基于Vue2.0的分页插件pagination.js 由于项目需求,要求使用 Vue2.0 开 ...
- CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法
因业务需求,要在 vue2.0 的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用.因 CKEditor5 文档比较少,此处记录下引用和一些基本用法. CKEdit ...
- vue2.0项目 calendar.js(日历组件封装)
最近一直闲来无事,便寻思着做一下自己的个人项目,也想说能使用现在比较流行的一些mvvm框架来做,于是就选用了这样的一个技术栈vue2.0+vue-router+vuex+webpack来做,做得也是多 ...
- vue2.0自定义指令
前面一片文章说了vue2.0过滤器,其实自定义指令跟过滤器非常相似,单就定义方式而言,其与过滤器完全一致,分为局部指令,和全局指令.不过就是filter改为directive的区别. 过滤器一般用于对 ...
- vue2.0 自定义 图片上传(UpLoader)组件
1.自定义组件 UpLoader.vue <!-- 上传图片 组件 --> <template> <div class="vue-uploader"& ...
- vue2.0 自定义 弹窗(MessageBox)组件
组件模板 src/components/MessageBox/index.vue <!-- 自定义 MessageBox 组件 --> <template> <div c ...
- vue2.0 自定义 饼状图 (Echarts)组件
1.自定义 图表 组件 Echarts.vue <!-- 自定义 echart 组件 --> <template> <div> <!-- echart表格 ...
随机推荐
- 01-python进阶-拾遗
列表复习append(x)追交到链尾extend(L)追加一个列表 等价于 +=insert(i,x)在位置i处插入xremove(x) 删除一个值为x的元素 如果没有抛出异常sort() 直接修改列 ...
- 正在创建模型,此时不可使用上下文“的解决办法。 正在创建模型,此时不可使用上下文。如果在 OnModelCreating 方法内使用上下文或如果多个线程同时访问同一上下文实例,可能引发此异常。请注意不
//默认为: Database.SetInitializer<testContext>(null);//这里报错, 检查原因:catch(Exception ex) 错误提示: 基础连接未 ...
- 【bzoj4785】[Zjoi2017]树状数组 线段树套线段树
题目描述 漆黑的晚上,九条可怜躺在床上辗转反侧.难以入眠的她想起了若干年前她的一次悲惨的OI 比赛经历.那是一道基础的树状数组题.给出一个长度为 n 的数组 A,初始值都为 0,接下来进行 m 次操作 ...
- 【Luogu】P2536病毒检测(Trie上DP)
题目链接 这道题我写了个01DP,f[i][j]表示跑到Trie上第i个节点,匹配到字符串第j位行不行 然后重点在*号无限匹配怎么处理 经过一番脑洞我们可以发现*号无限匹配可以拆成两种情况: 1:匹配 ...
- web 工程中利用Spring的 ApplicationContextAware接口自动注入bean
最常用的办法就是用 ClassPathXmlApplicationContext, FileSystemClassPathXmlApplicationContext, FileSystemXmlApp ...
- foj 2144 三位几何+区间覆盖
题目大意:一个人站在三维坐标系下的原点处用炮打蚊子,给出n个蚊子的起始坐标跟单位时间匀速移动的方向向量,距离他R以内的蚊子都可以打到,不过他也需要休息,没蚊子的时候也可以休息下.求他要起来多少次打蚊子 ...
- mybatis如何传入一个list参数
<!-- 7.2 foreach(循环List<String>参数) - 作为where中in的条件 --> <select id="getStudentLi ...
- linux c 正则表达式
#include <stdio.h> #include <regex.h> #include <mhash.h> int main() { regex_t rgx; ...
- 【CF725D】Contest Balloons(贪心,堆)
题意:acm队伍可以得气球,相同气球数是一个排名.每个队伍有一个气球数上限,如果该队伍的气球数大于上限 该队伍被淘汰.给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名. (2 ≤ n ≤ 3 ...
- Lua中闭包详解 来自RingOfTheC[ring.of.the.c@gmail.com]
这些东西是平时遇到的, 觉得有一定的价值, 所以记录下来, 以后遇到类似的问题可以查阅, 同时分享出来也能方便需要的人, 转载请注明来自RingOfTheC[ring.of.the.c@gmail.c ...