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表格 ...
随机推荐
- Leetcode 479.最大回文数乘积
最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x 91 = ...
- dp好题 玲珑杯 Expected value of the expression
152 - Expected value of the expression Time Limit:2s Memory Limit:128MByte Submissions:135Solved:65 ...
- UITabBarController支持旋转
1.默认的UITabBarController不支持四个方向,但可以给UITabBarController增加一个类别,实现旋转:具体做法: 在工程添加一个.h和.m文件如下: //Rotation. ...
- 【bzoj4269】再见Xor 高斯消元求线性基
题目描述 给定N个数,你可以在这些数中任意选一些数出来,每个数可以选任意多次,试求出你能选出的数的异或和的最大值和严格次大值. 输入 第一行一个正整数N. 接下来一行N个非负整数. 输出 一行,包含两 ...
- BZOJ3505 & 洛谷P3166 [Cqoi2014]数三角形 【数学、数论】
题目 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. 输入格式 输入一行,包含两个空格分隔的正整数m和n. 输出格式 输出 ...
- [转] 细说linux挂载——mount
转载的文章不能分类 这点比较坑 暂时先发到随笔里了 标题会标注的 找到一篇写的对挂载比较好的文章 收藏ing 作者:adagio Ubuntu社区 原帖网址:http://forum.ubu ...
- C语言实验报告二
实验一:第11次实验作业报告 题目:方阵循环右移 实验要求:将给定n×n方阵中的每个元素循环向右移m个位置,即将第0.1.⋯.n−1列变换为第n−m.n−m+1.⋯.n−1.0.1.⋯.n−m−1列. ...
- 手機 停充的種類 與 量測 power consumption 功率 使用 bq25896 bq25890
Precondition : 配有 power path 功能的 BQ2589 手機. 接上 pc usb port. Origin : 今天有同事問我, 手機是否可以在接上 pc usb port ...
- Yii CDbCriteria的常用方法总结
查看代码 打印 01 $criteria=new CDbCriteria; 02 $criteria->addCondition("id=1");//查询条件,即wher ...
- Requery,Refresh,Adoquery.Close,Open 区别
经过测试发现: Requery 相当于 Adq.Close,Open:并且比Close,Open方法有个优点就是不丢失排序,Sort Adq.Close,Open 后,原来的 Adq.Sort 会丢失 ...