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" />
相关推荐
程序员爱钓鱼26 分钟前
配置 GoLand 与 VS Code 开发环境
前端·后端·go
张人玉29 分钟前
基于 Vue 3 + ECharts + Express + SQLite 构建的鞋类零售数据分析与毛利预测平台——基于深度学习的鞋类销售数据分析系统
vue.js·sqlite·echarts·express
程序员爱钓鱼33 分钟前
Rust Vec 动态数组详解:创建、增删、遍历与排序
前端·后端·rust
LaughingZhu1 小时前
Product Hunt 每日热榜 | 2026-07-23
前端·神经网络·react.js·搜索引擎·前端框架
To_OC1 小时前
拼路径读文件总踩坑?我把 Node 的 path 和 fs 彻彻底底捋了一遍
javascript·后端·node.js
自然 醒1 小时前
记录We码开发者工具的一个bug
前端·javascript·bug
葡萄城技术团队1 小时前
HTML元素单元格:用自定义 CellType 扩展 SpreadJS 的显示能力
前端·javascript·html
不好听6131 小时前
Fragment:React 的 `<></>` 和原生的 DocumentFragment,同名不同命
前端·react.js·dom
不好听6131 小时前
useState 完全解析:初始化、异步更新、以及为什么传函数能解决闭包问题
前端·react.js
神明不懂浪漫3 小时前
【第七章】Java中的常用类
java·开发语言·前端·经验分享·笔记