VUE封装ElementUI中的Dialog表单弹窗
2020-06-08 04:50
816 查看
第一步,我们先搭建好手脚架以及把需要的elementUI也映入进来。
- vue的手脚架搭建大家可参考:使用vue-cli搭建vue项目完整版或者官方的网站
- elementUI的引入也挺简单的,大家可以直接去官方网站就可以找到引入的方法。
第二步,在components中建立一个vue文件,然后可以去elementUI的官网中把Dialog组件中的表单弹窗复制过来
<template> <div> <el-dialog :modal="true" :modal-append-to-body="true" :title="tittle" :visible.sync="isShow" :width="width" :height="height" :close-on-click-modal="false" :show-close="true" :close-on-press-escape="true" center> <el-form :model="form"> <el-form-item label="活动名称" :label-width="formLabelWidth"> <el-input v-model="form.name" autocomplete="off"></el-input> </el-form-item> <el-form-item label="活动区域" :label-width="formLabelWidth"> <el-select v-model="form.region" placeholder="请选择活动区域"> <el-option label="区域一" value="shanghai"></el-option> <el-option label="区域二" value="beijing"></el-option> </el-select> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="quxiao()">取 消</el-button> <el-button type="primary" @click="sumbim()">确 定</el-button> </div> </el-dialog> </div> </template> <script> export default { props: { isShow: { type: Boolean, default: true }, switchStyle: { type: Boolean, default: true }, tittle: { type: String, default: '新增' }, width: { type: String, default: "35%" }, height: { type: String, default: "1000px" }, }, data(){ return { form: { name: '', region: '', }, isShow:'', formLabelWidth: '120px' } }, methods: { sumbim(){ this.isShow = false }, quxiao(){ this.isShow = false } } } </script> <style scoped> .divauto{ margin: 10px auto 0 auto; } </style>
第三步,把组件引入到父组件的中script中以及在components函数中声明他
import dia from "@/components/xxx.vue";//引入组件 components: { dia } //在export default的components函数中声明组件
第四步,在父组件中的template加入组件dia
<dia :title="tittle" :isShow="isShow" :width="width" :height="height"></dia> //在data中声明变量 tittle:"新增", isShow:false, width:"60%", height:"2000px",
第五步,给button加一个点击事件,让表单弹窗显示
show(){ this.isShow=true; this.isShow== !this.isShow; }
到这里这个案例就可以简单的结束了。
相关文章推荐
- Vue项目elementUI中封装表单验证
- Vue 2.x折腾记 - (17) 基于Ant Design Vue 封装一个配置式的表单组件
- vue element dialog弹框 表单 编辑后再点击新增 表单无法重置问题
- Android仿支付宝微信支付密码界面弹窗封装dialog
- Vue.component(封装一个全局组件-弹窗)
- 封装vue的弹窗组件
- 问题杂记-Vue父子组件传值(ElementUI-Dialog)
- vue + elementui实现dialog自适应窗口的效果
- 基于Vue,ElementUI开发的一款表单设计器
- Vue2.0+ElementUi封装table组件实现分页功能
- Vue2.0+ElementUI简单form表单验证
- 217_把充满屏幕的底部dialog弹窗封装起来
- TDialog: DialogFragment封装,高效实现各种弹窗效果.md
- vue封装 element-ui form表单验证 正则匹配手机号 自定义校验表格内容
- 基于SpringCloud+vue(ElementUI)+mySQL前后端分离设计之--前端Fetch请求封装
- vue+element弹窗中表单校验遇到使用$nextTick的典型情景
- Vue 2.x折腾记 - (16) 基于Ant Design Vue 封装一个配置式的表单搜索组件
- 使用vue表单验证库async-validator封装Form表单组件
- ExtJs 备忘录(2)—— Form表单(二) [ 控件封装 ]
- vue结合bootstrap表单验证 FormValidation 图片验证