当前位置:网站首页 > 后端开发 > 正文

dialog的二次封装

一,使用效果

多个页面要使用这样的弹窗效果,所以需要封装一个dialog
在这里插入图片描述

二,实现代码

1,初步封装

<template> <div class="comDialog"> <!-- 编辑/新增 弹框 --> <el-dialog :visible.sync="visible" :width="width" :close-on-click-modal="closeOnClickModal" :show-close="false"> <div slot="title" class="dialog-title"> { 
   { 
   title}} </div> <div> <slot></slot> </div> <div slot="footer"> <div class="tan_dialog"> <slot name="leftButton"></slot> <el-button @click="cancel" type="info" class="tan_cal">取 消</el-button> <el-button type="primary" @click="visibleSure" class="tan_sure">{ 
   { 
   sureBtn}}</el-button> </div> </div> </el-dialog> </div> </template> <script> export default { 
    props: { 
    title: String, value: { 
    type: Boolean, default: false }, width:{ 
    type: String, default: '660' }, closeOnClickModal:{ 
    type:Boolean, default:true }, sureBtn:{ 
    type: String, default: '确 定' }, }, data() { 
    return { 
    visible: this.value }; }, mounted() { 
    }, watch: { 
    value() { 
    this.visible = this.value; }, visible: { 
    handler(newName) { 
    this.$emit("input", newName); }, deep: true } }, methods: { 
    visibleSure() { 
    this.$emit("confirm"); }, cancel(){ 
    this.$emit('cancel'); setTimeout(()=>{ 
    this.visible=false },0) } } }; </script> <style scoped> </style> 

2,对应不同业务的再处理

<template> <div> <!-- 添加 / 编辑 类目弹框 --> <com-dialog :title="title" v-model="dialogVisible" @confirm="confirm"> <div class="form_dialog"> <el-form ref="dialogVisiForm" label-width="120px" :rules="rules" :model="Form"> <el-form-item label="种类 :" prop="category"> <el-input v-model="Form.category"></el-input> </el-form-item> <el-form-item label="标题 :" prop="title"> <el-input v-model.number="Form.title" ></el-input> </el-form-item> <el-form-item label="类型 :" prop="type"> <el-input v-model="Form.type"></el-input> </el-form-item> <el-form-item label="打印机编号 :" prop="number"> <el-input v-model.number="Form.number"></el-input> </el-form-item> <el-form-item label="打印机密钥 :" prop="password"> <el-input v-model.number="Form.password"></el-input> </el-form-item> <el-form-item label="打印联数 :" prop="amount"> <el-input v-model.number="Form.amount"></el-input> </el-form-item> </el-form> </div> </com-dialog> </div> </template> <script> import comDialog from "@/components/comDialog"; export default { 
    components: { 
    comDialog }, props: { 
    value: { 
    type: Boolean, default: false }, title: { 
    type: String, default: "" }, propsFrom:{ 
    default: { 
    category: "", title: '', type: "", number: "", password: "", amount: "" } } }, data() { 
    return { 
    dialogVisible: this.value, Form: this.propsFrom, rules: { 
    category: [{ 
    required: true, message: "请输入种类", trigger: "blur" }], number: [{ 
    required: true, message: "请输入打印机编号", trigger: "blur" }], password: [{ 
    required: true, message: "请输入打印机编号", trigger: "blur" }], amount: [{ 
    required: true, message: "请输入打印机编号", trigger: "blur" }] } }; }, methods: { 
    confirm(){ 
    this.$refs['dialogVisiForm'].validate((valid) => { 
    if (valid) { 
    this.$emit("getConfirm", this.Form); } else { 
    console.log('error submit!!'); return false; } }); } }, watch: { 
    propsFrom(val){ 
    this.Form=val }, value() { 
    this.dialogVisible = this.value; }, dialogVisible: { 
    handler(newName) { 
    this.$emit("input", newName); }, deep: true } } }; </script> <style scoped lang="less"> .line{ 
    .spanLine{ 
    display: block; text-align: center; color: #; } } </style> 

3,具体项目页面的使用

import dialogComponent from "./dialogComponent.vue"; export default { 
    components: { 
    dialogComponent }, 

 <!-- 编辑对话框 --> <dialog-component title="编辑打印机" v-model="dialogVisible" @getConfirm="getConfirm" :propsFrom="form" ref="formRef"> </dialog-component> 
到此这篇dialog的二次封装的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • uniapp实现滑动导航2024-11-29 20:45:10
  • 实现滑动到中间变大的效果2024-11-29 20:45:10
  • uniapp实现点击回到顶部2024-11-29 20:45:10
  • uniapp某个页面高度占满写法2024-11-29 20:45:10
  • vant组件二次封装-下拉刷新列表组件2024-11-29 20:45:10
  • nginx个人常用2024-11-29 20:45:10
  • 黑马品优购项目的总结-首页2024-11-29 20:45:10
  • 伪元素2024-11-29 20:45:10
  • 黑马品优购项目的总结二2024-11-29 20:45:10
  • vant ui的dialog二次封装使用2024-11-29 20:45:10
  • 全屏图片