vue实现模态框的通用写法
来源:互联网 发布:长距离传输网络信号 编辑:程序博客网 时间:2024/06/16 00:22
在看了element组件的源码后发现,所有模态框其实实现方法都差不多,主要用到了vue在组件化上的双向绑定。代码:
<!--查看槽点对话框--><template lang="html"> <transition name="el-fade-in-linear"> <div draggable="true" @drag="mouseDrag" @dragend="mouseDragend" :style="dialogStyle" class="g-dialog-wrapper" v-show="myVisible"> <div class="g-dialog-header"> <div class="left"> 模态框 </div> <div class="right"> <i class="g-times-icon fa fa-times" @click="myVisible=false" aria-hidden="true"></i> </div> </div> <div class="g-dialog-container"> </div> </div> </transition></template><script> export default { props: { visible: Boolean }, created() { }, data() { return { myVisible: this.visible, }, computed: {}, methods: { }, components: {}, watch: { myVisible: function (val) { this.$emit('update:visible', val) }, visible: function (val) { this.myVisible = val } } }</script><style lang="css" scoped></style>
上面代码主要的部分是watch里面的代码,实现监听数据变化,及时更新。所以在使用的时候就很方便了,在component注册组件之后:
<g-key-dialog :visible.sync="keyDialogVisible"></g-key-dialog>
注:这里必须使用sync,要不是无法双向绑定的
阅读全文
0 0
- vue实现模态框的通用写法
- makefile的通用写法
- 通用ViewHolder的写法
- VUE 页面的跳转写法
- python代码的通用写法
- Makefile的一种通用写法
- iOS中单例的通用写法
- 通用的ViewHolder工具写法
- 一个通用的Makefile写法
- Android 通用Dialog的写法
- springboot的通用BaseDAO写法
- Linux的Epoll的通用写法
- android解析xml的通用写法
- jquery checkbox 全选/全不选 的通用写法
- 数据录入窗口的通用写法
- 数据录入窗口的通用写法[转载]
- 数组元素查找的通用写法举例
- 测试junit类的通用写法
- Oracle使用navicat建表查询时表不存在
- 服务器端接入有盟推送,实现为android 和 ios推送的功能
- imageLoader自定义配置
- C# 访问修饰符internal的访问范围误区释疑
- sql concat() 函数解释
- vue实现模态框的通用写法
- Spring 系列: Spring 框架简介
- RESTEASY ,从学会使用到了解原理。
- java知识点整理(持续更新)
- Imagerloader将图片存到sd卡并且可以清除
- -bash fork 无法分配内存
- java时间处理
- 安卓中集中图片加载框架的比较
- 在maven项目基础上搭建springmvc+mybatis项目