• vue实现弹窗的动态导入(:is=“dialogName“)


    组件的动态挂载

    弹窗aaa.vue

    <template>
      <el-dialog
        width="700px "
        v-dialog-out
        destroy-on-close
        v-if="dialogVisible"
        :title="title"
        :visible="dialogVisible"
        :before-close="hideDialog"
        :close-on-click-modal="false"
      >
        <div class="dialog-body">
          
        </div>
    
        <div class="dialog-footer">
          <el-button @click="hideDialog">取 消</el-button>
          <el-button type="primary" @click="validateForm">确 定</el-button>
        </div>
      </el-dialog>
    </template>
    
    <script>
    export default {
      name: "aaa",
      components: {},
      props: {},
      data() {
        return {
          dialogVisible: false,
          title: "",
        };
      },
      methods: {
        showDialog(data) {
          console.log(data);
          this.dialogVisible = true;
          this.title = data.type;
          if (data.data) {
            this.getDetail(data.data.id);
          }
        },
    
        hideDialog() {
          this.dialogVisible = false;
          this.$refs.form.resetFields();
          this.formData = {};
          this.$parent.getTableData();
          this.fileUploadUtils.fileList = [];
        },
    
        getDetail(id) {
        },
    
        async validateForm() {
          try {
            if (await this.$refs.form.validate()) this.submitForm();
          } catch (e) {}
        },
    
        submitForm() {
        },
      },
      created() {},
      mounted() {},
    };
    </script>
    
    <style lang="scss" scoped>
    ::v-deep .el-dialog__body {
      padding: 20px 0 0 !important;
    }
    
    .dialog-body {
      padding: 0 20px;
      max-height: 65vh;
      overflow-y: auto;
    }
    
    .dialog-footer {
      text-align: center;
      padding: 10px 0 18px;
    }
    </style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85

    弹窗bbb.vue

    <template>
      <el-dialog
        width="700px "
        v-dialog-out
        destroy-on-close
        v-if="dialogVisible"
        :title="title"
        :visible="dialogVisible"
        :before-close="hideDialog"
        :close-on-click-modal="false"
      >
        <div class="dialog-body">
          
        </div>
    
        <div class="dialog-footer">
          <el-button @click="hideDialog">取 消</el-button>
          <el-button type="primary" @click="validateForm">确 定</el-button>
        </div>
      </el-dialog>
    </template>
    
    <script>
    export default {
      name: "bbb",
      components: {},
      props: {},
      data() {
        return {
          dialogVisible: false,
          title: "",
        };
      },
      methods: {
        showDialog(data) {
          console.log(data);
          this.dialogVisible = true;
          this.title = data.type;
          if (data.data) {
            this.getDetail(data.data.id);
          }
        },
    
        hideDialog() {
          this.dialogVisible = false;
          this.$refs.form.resetFields();
          this.formData = {};
          this.$parent.getTableData();
          this.fileUploadUtils.fileList = [];
        },
    
        getDetail(id) {
        },
    
        async validateForm() {
          try {
            if (await this.$refs.form.validate()) this.submitForm();
          } catch (e) {}
        },
    
        submitForm() {
        },
      },
      created() {},
      mounted() {},
    };
    </script>
    
    <style lang="scss" scoped>
    ::v-deep .el-dialog__body {
      padding: 20px 0 0 !important;
    }
    
    .dialog-body {
      padding: 0 20px;
      max-height: 65vh;
      overflow-y: auto;
    }
    
    .dialog-footer {
      text-align: center;
      padding: 10px 0 18px;
    }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84

    父组件中使用

    <template> 
    	<div>
         	<el-button
              type="text"
              size="small"
              icon="iconfont if-biaodancaozuo-xiugai"
              @click="doSomething(scope.row, '审批', 'aaa')"
              >审批
            </el-button>
    
            <el-button
              type="text"
              size="small"
              icon="iconfont if-biaodancaozuo-xiugai"
              @click="doSomething(scope.row, '修改', 'bbb')"
              >修改
            </el-button>
            
            
    		<component :is="dialogName" ref="dialog"></component>
        </divd>	
    </template>	
    
    	export default {
    		data() {
    			return {
    				dialogName: undefined,
    			}
    		},
    
            methods: {
                doSomething(data, type, dialogName) {
                  this.dialogName = this.getDialog(dialogName);
                  this.$nextTick(() => {
                    this.$refs.dialog.showDialog({ data, type });
                  });
                },
    
                getDialog(name) {
    				// 替换成你自己的路径, name 就是组件名:aaa/bbb.vue
                	return require(`@/views/maintenanceProject/engineeringManage/dialog/${name}.vue`).default;
                },
            }
        }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
  • 相关阅读:
    【前端验证】通关寄存器与ral_model —— 生成的RTL代码分析(1)
    最新SQL注入漏洞原理及与MySQL相关的知识点
    将Apache访问日志保存到MySQL数据库
    Redis变慢怎么办?
    Docker 基础命令操作
    【InnoDB Cluster】修改已有集群实例名称及成员实例选项
    HUDI(搭建详细记录附加jar)
    手把手让你实现postfix+extmail+mysql虚拟用户邮件体系
    [RK3568][Android11]内核Oops日志分析
    Java8新特性
  • 原文地址:https://blog.csdn.net/m0_74149462/article/details/138115844