vue3 抽取el-dialog子组件

vue3 抽取el-dialog子组件

  • 自定义弹窗组件myDialog.vue
html 复制代码
<template>
  <el-dialog :model-value="visible" title="新增" width="600px" :before-close="handleBeforeClose" destroy-on-close>
    <el-form ref="rowformRef" :model="rowForm" label-position="top" :rules="rules">
      <el-form-item label="名称" prop="name">
        <el-input v-model="rowForm.name" placeholder="请输入名称" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSubmit">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, defineProps } from 'vue';

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
});
const emit = defineEmits(['update:visible']);

const rules = ref({
  name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
});
const rowformRef = ref(null);
const rowForm = ref({});

const handleSubmit = () => {
  rowformRef.value.validate((valid) => {
    if (valid) {
    }
  });
};

const handleBeforeClose = (done) => {
  done();
  emit('update:visible', false);
};

const handleClose = () => {
  emit('update:visible', false);
};
</script>

<style lang="scss" scoped>
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
</style>
  • 使用弹窗组件
html 复制代码
<myDialog v-model:visible="dialogVisible" />
相关推荐
lecepin2 小时前
AI Coding 资讯 2025-11-05
前端·javascript
excel2 小时前
Vue 模板解析器 parserOptions 深度解析
前端
前端小咸鱼一条2 小时前
17.React获取DOM的方式
前端·javascript·react.js
excel2 小时前
Vue 编译核心中的运行时辅助函数注册机制详解
前端
excel2 小时前
🌿 深度解析 Vue DOM 编译器模块源码:compile 与 parse 的构建逻辑
前端
excel2 小时前
深度解析 Vue 编译器中的 transformShow:v-show 指令的编译原理
前端
excel2 小时前
深度解析:decodeHtmlBrowser —— 浏览器端 HTML 解码函数设计
前端
excel2 小时前
深度解析:Vue 模板编译器中的 transformVText 实现原理
前端
excel2 小时前
深度解析:isValidHTMLNesting —— HTML 嵌套合法性验证的设计与实现
前端