vue自定义抽屉组件
<template>
<div class="drawer">
<div :class="maskClass" @click="closeByMask"></div>
<div :class="mainClass" :style="mainStyle" class="main">
<div class="drawer-head">
<span>{{ title }}</span>
<span
v-show="closable"
class="close-btn"
@click="closeByButton"
>x</span>
</div>
<div class="drawer-body" :style="bodyStyle">
<slot />
</div>
</div>
</div>
</template>
<script>
export default {
name: 'drawer',
props: {
// 是否打开
display: {
type: Boolean
},
// 标题
title: {
type: String,
default: '标题'
},
// 是否显示关闭按钮
closable: {
type: Boolean,
default: true
},
// 是否显示遮罩
mask: {
type: Boolean,
default: true
},
// 是否点击遮罩关闭
maskClosable: {
type: Boolean,
default: true
},
// 宽度
width: {
type: String,
default: '400px'
},
// 高度
height: {
type: String,
default: '75%'
},
// 是否在父级元素中打开
inner: {
type: Boolean,
default: false
}
},
computed: {
maskClass: function () {
return {
'mask-show': this.mask && this.display,
'mask-hide': !(this.mask && this.display),
inner: this.inner
}
},
mainClass: function () {
return {
'main-show': this.display,
'main-hide': !this.display,
inner: this.inner
}
},
mainStyle: function () {
return {
width: this.width,
height: this.height,
bottom: this.display ? '0' : `-${this.height}`,
borderTop: this.mask ? 'none' : '1px solid #eee'
}
},
bodyStyle: function () {
return {
height: this.height
}
}
},
mounted () {
if (this.inner) {
let box = this.$el.parentNode
box.style.position = 'relative'
}
},
methods: {
closeByMask () {
this.maskClosable && this.$emit('update:display', false)
},
closeByButton () {
this.$emit('update:display', false)
}
}
}
</script>
<style lang="less" scoped>
.drawer {
.mask-show {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
background-color: rgba(0, 0, 0, 0.5);
opacity: 1;
transition: opacity 0.5s;
}
.mask-hide {
opacity: 0;
transition: opacity 0.5s;
}
.main {
position: fixed;
z-index: 10;
bottom: 0;
height: 100%;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background: #f7f7f7;
transition: all 0.5s;
}
.main-show {
opacity: 1;
}
.main-hide {
opacity: 0;
}
.inner {
position: absolute;
}
.drawer-head {
display: flex;
justify-content: space-between;
align-items: center;
height: 50px;
padding: 20px;
box-sizing: border-box;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
font-size: 16px;
font-weight: bold;
background: #fff;
position: relative;
border-bottom: 1px solid #eee;
.close-btn {
font-size: 24px;
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
display: inline-block;
cursor: pointer;
}
}
.drawer-body {
// padding: 20px;
font-size: 14px;
overflow: auto;
}
}
</style>
import drawer from './drawer' components: { drawer }, display: true,
drawerWidth: '100%',
drawerHeight: '500px', <el-button type="primary" @click="display = !display">{{display?'close': 'open'}}</el-button>
<drawer title="我是标题" :display.sync="display" :width="drawerWidth" :height="drawerHeight">
<div>123</div>
</drawer>
cnpm install stylus-loader css-loader style-loader --save-dev
cnpm install less less-loader --save-dev
第二种方案:
<template>
<div class="drawer">
<button @click="clickBtn">点击</button> <div class="background" v-if="open" @click.self="closeDrop">
<div class="drop" :class="{ active: isActive, close: isClose }">drop</div>
</div>
</div>
</template> <script>
export default {
name: 'HelloWorld',
props: {},
data () {
return {
open: false,
isActive: false,
isClose: false
}
},
methods: {
clickBtn () {
this.open = true
this.isActive = true
this.isClose = false
},
closeDrop () {
this.isClose = true
setTimeout(() => {
this.open = false
}, 200)
}
}
}
</script> <style scoped lang="scss">
.background {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba($color: #000000, $alpha: 0.5);
.drop {
width: 0px;
position: absolute;
top: 0;
right: 0;
bottom: 0;
background: #fff;
}
// 开
.active {
animation: opendoor 0.3s normal forwards;
}
@keyframes opendoor {
from {
width: 0;
}
to {
width: 45%;
}
}
// 关
.close {
animation: close 0.3s normal forwards;
}
@keyframes close {
0% {
width: 45%;
}
100% {
width: 0;
opacity: 0;
}
}
}
</style>
vue自定义抽屉组件的更多相关文章
- vue自定义全局组件(自定义插件)
有时候我们在做开发的时候,就想自己写一个插件然后就可以使用自己的插件,那种成就感很强.博主最近研究element-ui和axios的时候,发现他们是自定义组件,但是唯一有一点不同的是,在用elemen ...
- vue 自定义报警组件
1.自定义报警组件 Alarm.vue <!-- 报警 组件 --> <template> <div class="alarm"> <!- ...
- vue自定义select组件
1.目的 看了很多element-ui的源码,决定自己实现一个简单的select组件,遇到的几个难点,便记录下来. 2.难点一 element-ui中的select组件通过v-model可以绑定数据, ...
- vue 自定义分页组件
vue2.5自定义分页组件,可设置每页显示条数,带跳转框直接跳转到相应页面 Pagination.vue 效果如下图: all: small(只显示数字和上一页和下一页): html <temp ...
- Vue自定义日历组件
今天给大家介绍Vue的日历组件,可自定义样式.日历类型及支持扩展,可自定义事件回调.Props数据传输. 线上demo效果 示例 Template: <Calendar :sundayStart ...
- vue自定义分页组件---切图网
vue2.5自定义分页组件 Pagination.vue,可设置每页显示条数,带跳转框直接跳转到相应页面,亲测有用.目前很多框架自带有分页组件比如elementUI,不过在面对一个拿到PSD稿,然后重 ...
- vue自定义日期组件
vue-datepicker 基于 vuejs 2.x 可自定义主题的日期组件 github Usage 只需要在项目中加入 calendar.vue,就可以使用了. 向组件传入 prop 即可改变 ...
- vue 自定义image组件
介绍 1:当图片加载失败时,给出错误提示. 2:当图片加载中时,给出加载提示. 3:图片处理模式:等比缩放/裁剪/填充/... 1.图片加载状态处理 通过给图片绑定load事件与error事件处理函数 ...
- vue 自定义封装组件 使用 model 选项
自定义组件的 v-model 一个组件上的 v-model 默认会利用名为 value 的 prop 和名为 input 的事件,但是像单选框.复选框等类型的输入控件可能会将 value 特性用于不同 ...
随机推荐
- VMware Workstation 官方正式版及激活密钥
热门虚拟机软件VMware Workstation Pro现已更新至14.1.2,14.0主要更新了诸多客户机操作系统版本,此外全面兼容Wind10创建者更新.12.0之后属于大型更新,专门为Win1 ...
- Flask学习 3 url_for的使用
#!/usr/bin/env python # encoding: utf-8 """ @version: v1.0 @author: cxa @file: flask0 ...
- 测开之路八十二:匿名函数:lambda表达式
# 匿名函数:lambda表达式# lambda 参数: 逻辑f = lambda name: print(name)f('tom') f2 = lambda x, y: x + yprint(f2( ...
- Jmeter接口自动化培训
课程前提 速成班,讲的不会非常深,每个人基础不一样,但是实现接口自动化没有问题,因为jmeter更多的用来做性能测试.当然有兴趣我们也可以穿插一点 课程基本大纲 接口基础概念 部署本地测试环境(使用d ...
- 【SD系列】SAP SD模块-创建供应商主数据BAPI
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SD系列]SAP SD模块-创建供应商主数据B ...
- 【python】含中文字符串截断
对于含多字节的字符串,进行截断的时候,要判断截断处是几字节字符,不能将多字节从中分割,避免截断后乱码 下面给出utf8和gb18030上的实现, 用任何一种都可以,可以先进行转码,用encode, d ...
- Eclipse+Pydev环境下出现error “eclipse Non-UTF-8 code”
文件首行加上”#coding=utf-8” ,这一句话可控制代码中可输入中文字符
- Oracle基本操作练习(一)
--创建表空间 create tablespace test datafile 'c:\test.dbf' size 100m autoextend on next 10m; --删除表空间 drop ...
- 《JAVA设计模式》之建造模式(Builder)
在阎宏博士的<JAVA与模式>一书中开头是这样描述建造(Builder)模式的: 建造模式是对象的创建模式.建造模式可以将一个产品的内部表象(internal representation ...
- 解决ubuntu下eth0不显示
今天电脑重启之后,用ifconfig查看网络地址,就发现eth0神奇的消失了,顿时感觉吓尿了. 按照网上看到的资料,发现输入ifconfig -a 发现可以显示eth0,但是当输入ifconfig就没 ...