vue.js实现简易折叠面板
作者:曲小强 发布时间:2024-05-08 09:33:47
标签:vue.js,折叠面板
本文实例为大家分享了vue.js实现简易折叠面板的具体代码,供大家参考,具体内容如下
代码如下:
主文件:app.vue
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<collpase>
<collpase-item
:title="item.name"
:showAnimation="true"
v-for="(item, i) in chapterList"
:key="i"
>
<div class="list" v-for="(it, index) in item.list" :key="index">
{{it.name}}
</div>
</collpase-item>
</collpase>
</div>
</template>
<script>
import Collpase from './components/Collpase.vue';
import CollpaseItem from './components/CollpaseItem.vue'
export default {
name: 'App',
data() {
return {
chapterList: [
{
name: '标题一',
list: [
{
name: '是是是是是是所'
},
{
name: '啊啊啊啊'
}
]
},
{
name: '标题二',
list: [
{
name: '是是是是是是所'
},
{
name: '啊啊啊啊'
},
{
name: '啊啊啊啊'
}
]
}
]
}
},
components: {
Collpase,
CollpaseItem,
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
子组件:
<template>
<div class="collapse">
<slot />
</div>
</template>
<script>
export default {
name: 'Collapse',
props: {
accordion: {
type: [Boolean, String],
default: false
}
},
provide() {
return {
collapse: this
}
},
created() {
this.childrens = []
},
methods: {
onChange() {
let activeItem = []
this.childrens.forEach((vm) => {
if (vm.isOpen) {
activeItem.push(vm.nameSync)
}
})
this.$emit('change', activeItem)
}
}
}
</script>
<style lang="css" scoped>
.collapse {
width: 100%;
display: flex;
flex: 1;
flex-direction: column;
}
</style>
子组件:
<template>
<div>
<div :class="{ 'collapse-disabled': disabled,'collapse-cell--notdisabled': !disabled, 'collapse-cell--open': isOpen,'collapse-cell--hide':!isOpen }" class="collapse-cell">
<div :class="{ 'collapse-disabled': disabled}" class="collapse-cell__title" @click="onClick">
<span class="collapse-cell__title-text">{{ title }}</span>
<img :class="{ 'active': isOpen, 'active-animation': showAnimation === true }" class="title-arrow" src="https://static-mumway.oss-cn-zhangjiakou.aliyuncs.com/NetworkFrontEnd/wsj/yslbq/btn_dropdown.png"/>
</div>
<div :class="{'collapse-cell__content--hide':!isOpen}" class="collapse-cell__content">
<div :class="{ 'active-animation': showAnimation === true }" class="collapse-cell__wrapper" :style="{'transform':isOpen?'translateY(0)':'translateY(-50%)','-webkit-transform':isOpen?'translateY(0)':'translateY(-50%)'}">
<slot />
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'UniCollapseItem',
props: {
title: {
// 列表标题
type: String,
default: ''
},
name: {
// 唯一标识符
type: [Number, String],
default: 0
},
disabled: {
// 是否禁用
type: Boolean,
default: false
},
showAnimation: {
// 是否显示动画
type: Boolean,
default: false
},
open: {
// 是否展开
type: Boolean,
default: false
},
thumb: {
// 缩略图
type: String,
default: ''
}
},
data() {
return {
isOpen: false
}
},
watch: {
open(val) {
this.isOpen = val
}
},
inject: ['collapse'],
created() {
this.isOpen = this.open
this.nameSync = this.name ? this.name : this.collapse.childrens.length
this.collapse.childrens.push(this)
if (String(this.collapse.accordion) === 'true') {
if (this.isOpen) {
let lastEl = this.collapse.childrens[this.collapse.childrens.length - 2]
if (lastEl) {
this.collapse.childrens[this.collapse.childrens.length - 2].isOpen = false
}
}
}
},
methods: {
onClick() {
if (this.disabled) {
return
}
if (String(this.collapse.accordion) === 'true') {
this.collapse.childrens.forEach(vm => {
if (vm === this) {
return
}
vm.isOpen = false
})
}
this.isOpen = !this.isOpen
this.collapse.onChange && this.collapse.onChange()
this.$forceUpdate()
}
}
}
</script>
<style lang="css" scoped>
.collapse-cell {
flex-direction: column;
border-color: #f0f0f0;
border-bottom-width: 1px;
}
.collapse-cell--open {
background-color: #fff;
}
.collapse-disabled {
cursor: not-allowed !important;
}
.collapse-cell--hide {
height: 48px;
}
.active-animation {
transition-property: transform;
transition-duration: 0.3s;
transition-timing-function: ease;
}
.collapse-cell__title {
border-bottom: 1px solid #f0f0f0;
padding: 12px 20px;
position: relative;
display: flex;
width: 100%;
box-sizing: border-box;
height: 44px;
line-height: 44px;
flex-direction: row;
justify-content: space-between;
align-items: center;
cursor: pointer;
}
.collapse-cell__title-img {
margin-right: 10px;
}
.title-arrow {
width: 22px;
height: 14px;
}
.active {
transform: rotate(180deg);
}
.collapse-cell__title-text {
flex: 1;
font-size: 16px;
margin-right: 16px;
white-space: nowrap;
color: #333333;
font-weight: bold;
lines: 1;
overflow: hidden;
text-overflow: ellipsis;
}
.collapse-cell__content {
overflow-x: hidden;
}
.collapse-cell__wrapper {
display: flex;
flex-direction: column;
}
.collapse-cell__content--hide {
height: 0px;
line-height: 0px;
}
</style>
来源:https://blog.csdn.net/quhongqiang/article/details/116591091


猜你喜欢
- 简介Casbin是一个强大的、高效的开源访问控制框架,其权限管理机制支持多种访问控制模型。casbin 的主要特性包括:支持自定义请求的格式
- 小小程序猿SQL Server认知的成长 1.没毕业或工作没多久,只知道有数据库、SQL这么个东东,浑然分不清SQL和Sql Server
- 两个例子package main import ( "fmt" "time")func Proces
- 1,IE使用attachEvent/detachEvent方法来添加和删除事件 * ;w3c使用addEventListener/remov
- startswith()方法Python startswith() 方法用于检查字符串是否是以指定子字符串开头如果是则返回 True,否则返
- 1、向List中添加元素的方法1.1 Python append()方法添加元素append() 方法用于在列表的末尾追加元素,该方法的语法
- 方法一:queue = forms.ModelChoiceField(label=u'队列',queryset=Queue.
- 背景有一个项目,今年12月份开始重构,项目涉及到了socket。但是socket用的是以前一个开发人员封装的包(这个一直被当前的成员吐槽为什
- 定义一个变量,直接输出会输出变量的属性,并不能输出变量值。那么怎么输出变量值呢?请看下面得意import tensorflow as tf
- 概要介绍mmpi,是一款使用python实现的开源邮件快速检测工具库,基于community框架设计开发。mmpi支持对邮件头、邮件正文、邮
- 需求手百小程序的toast仅支持在页中展示,不能自定义位置、字体大小、在单个文本中增加icon等需求;因此自定义一个全局可通用的Toast。
- TCP是用来计算机之间进行通信的,通过编写客户端和服务端聊天的代码,对于服务器与客户端的工作步骤有了深刻的了解,在这里根据了不起的Node.
- 附上官网地址:https://pytorch.org/docs/stable/index.html1.torch.squeezesqueez
- 本文实例讲述了Python操作MySQL数据库的两种方式。分享给大家供大家参考,具体如下:第一种 使用pymysql代码如下:import
- 1、执行环境说明python版本3.7直接使用pip进行安装pywin32、pyinstallerpip install pywin32pi
- python版本和ssl版本都会导致 requests在请求https网站时候会出一些错误,最好使用新版本。1 Python2.6x use
- 前言最近工作中遇到个需求是要得到一个类的静态属性,也就是说有个类 Type ,我要动态获取 Type.FTE 这个属性的值。最简单的方案有两
- 相信很朋友因为PyCharm最新激活码或激活补丁的安装参数每月都会失效而烦恼PyCharm最新激活码先分享个PyCharm最新激活码大家可以
- 代码如下:create proc p_sword_getblcolumn ( @tblN
- 在GIS中,栅格属性里有关于栅格自身的信息,背景(nodata value)对于识别一张图像的边界像元尤为重要,我们目的只要把每行每列中的第