注:因为项目中用的是 element-ui 框架,而这个框架并没有抽屉组件,所以自己实现一个。

一、源码地址

https://github.com/imxiaoer/DrawerForVue

二、效果图

三、具体代码

drawer.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 class="close-btn" v-show="closable" @click="closeByButton">X</span>
</div>
<div class="drawer-body">
<slot/>
</div>
</div>
</div>
</template> <script>
export default {
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'
}, // 是否在父级元素中打开
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,
right: this.display ? '0' : `-${this.width}`,
borderLeft: this.mask ? 'none' : '1px solid #eee'
}
}
},
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="scss" scoped>
.drawer {
/* 遮罩 */
.mask-show {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
background-color: rgba(0,0,0,.5);
opacity: 1;
transition: opacity .5s;
}
.mask-hide {
opacity: 0;
transition: opacity .5s;
} /* 滑块 */
.main {
position: fixed;
z-index: 10;
top: 0;
height: 100%;
background: #fff;
transition: all 0.5s;
}
.main-show {
opacity: 1;
}
.main-hide {
opacity: 0;
} /* 某个元素内部显示 */
.inner {
position: absolute;
} /* 其他样式 */
.drawer-head {
display: flex;
justify-content: space-between;
height: 45px;
line-height: 45px;
padding: 0 15px;
font-size: 14px;
font-weight: bold;
border-bottom: 1px solid #eee;
.close-btn {
display: inline-block;
cursor: pointer;
height: 100%;
padding-left: 20px;
}
}
.drawer-body {
font-size: 14px;
padding: 15px;
}
}
</style>

组件具体使用如下:

<template>
<div class="box">
<el-button type="primary" @click="display = true">打开抽屉</el-button>
<drawer title="我是一个抽屉组件" :display.sync="display" :inner="true" :width="drawerWidth" :mask="false">
1. Hello, world!
2. Do you like it?
</drawer>
</div>
</template> <script>
import drawer from '@/components/drawer/drawer'
export default {
components: { drawer },
data () {
return {
display: false,
drawerWidth: '500px'
}
}
}
</script>

VUE组件 之 Drawer 抽屉的更多相关文章

  1. 引用element-ui的Drawer抽屉组件报错问题

    前提:vue项目采取按需引入的方式引入element,并且使用其他组件都正常,没有发生异常 问题表现: 在vue项目中引用了Drawer 抽屉组件,结果报错 意思就是组件未注册,当时我的表情: 没办法 ...

  2. Flutter学习笔记(18)--Drawer抽屉组件

    如需转载,请注明出处:Flutter学习笔记(18)--Drawer抽屉组件 Drawer(抽屉组件)可以实现类似抽屉拉出和推入的效果,可以从侧边栏拉出导航面板.通常Drawer是和ListView组 ...

  3. 在被vue组件引用的 js 文件里获取组件实例this

    思路: 通过调用函数 把 组件实例this  传递 到 被应用的 js文件里 实例: 文件结构 在SendThis.vue 文件中引用 了modalConfig.js import modalConf ...

  4. webAPP如何实现移动端拍照上传(Vue组件示例)?

    摘要:使用HTML5编写移动Web应用,主要是为了尝试一下“一套代码多处运行”,一个webapp几乎可以不加修改的运行在PC/Android/iOS等上面运行.但是写到现在觉得虽然这种方式弊大于利,不 ...

  5. drawer 抽屉 弹框 在 modal的后面的解决方案

    drawer 抽屉 弹框 在 modal的后面的解决方案 方案1 在框内 弹出 <Drawer title="拍照" :transfer="false" ...

  6. Web应用界面好帮手!DevExtreme React和Vue组件全新功能上线

    行业领先的.NET界面控件DevExpress 正式发布了v19.1版本,本文将主要介绍DevExtremev19.1中React组件响应式应用程序布局模板及CLI工具.本地React图表,和Vue组 ...

  7. vue组件

    分享出来让思路更成熟. 首先组件是 Vue.js 最强大的功能之一. 可以减少很多的工作量,提高工作效率. 编写一个可复用性的组件,虽然官网上也有.... 编写可复用性的vue组件 具备一下的几个要求 ...

  8. vue组件的配置属性

    vue组件的声明语法: Vue.component('component-name',{ template:'<p>段落{{prop1}} {{prop2}}</p>', da ...

  9. vue组件,撸第一个

    实现此例您可以学到: vue-cli的基本应用 父组件如何向子组件传递值 单文件组件如何引入scss v-on和v-for的基础应用 源码下载 一.搭建vue开发环境 更换镜像到cnpmnpm ins ...

随机推荐

  1. 19.DjangoRestFramework学习二之序列化组件、视图组件

    一 序列化组件 首先按照restful规范咱们创建一些api接口,按照下面这些形式写吧: Courses --- GET ---> 查看数据----->返回所有数据列表[{},{},] C ...

  2. 【CSS】346- 你所不知道的 CSS 阴影技巧与细节

    偷懒了1个多礼拜,在工作饱和的情况下,怎么坚持学习?今天的分享来自@Coco国服第一切图仔,我们聊聊CSS属性box-shadow- 关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 ...

  3. Python流程控制之循环结构

    目录 while循环 for循环 嵌套循环 break.continue.pass 练习 当出现有规律或者是重复的事情就可以使用循环. 1.循环变量初始化 2.循环条件 3.循环体 4.改变循环变量 ...

  4. 回归损失函数2 : HUber loss,Log Cosh Loss,以及 Quantile Loss

    均方误差(Mean Square Error,MSE)和平均绝对误差(Mean Absolute Error,MAE) 是回归中最常用的两个损失函数,但是其各有优缺点.为了避免MAE和MSE各自的优缺 ...

  5. 移动端Vue图片获取,压缩,预览组件-upload-img(H5+获取照片,压缩,预览)

    组件示例图 组件代码 upload_img.vue <div id="uploadImg"> <div class="upload_image_box& ...

  6. 深入学习CSS3-flexbox布局

    学习博客:https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 学习博客:http://caibaojian.com/demo/flexbox ...

  7. 《Java基础知识》Java技术总结

    1. Java 知识点总结 Java标示符.保留字和数制:https://www.cnblogs.com/jssj/p/11114041.html Java数据类型以及变量的定义:https://ww ...

  8. Wonder暂停开发,开始写书

    公告 大家好,我们决定暂时停止开发Wonder,但会继续维护当前的Wonder版本(如继续维护官网.在线编辑器.QQ群等). 我们当前的主要任务是 写书:基于Wonder 1.0版本的开发经验,写一本 ...

  9. c++之基础数据类型

    c++规定了在创建一个变量或者常量时,必须先要指定相应的数据类型,否发无法将变量分配给内存. 1.整型 数据类型 占用空间 取值范围 short 2字节 -2^15-2^15-1 int 4字节 -2 ...

  10. 用Python抢到回家的车票,so easy!

    “ 盼望着,盼望着,春节的脚步近了,然而,每年到这个时候,最难的,莫过于一张回家的火车票. ​ 据悉,今年春运期间,全国铁路发送旅客人次同比将增长 8.0%.达到 4.4 亿人次. ​ 2020 年铁 ...