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" />
相关推荐
刘发财3 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶6 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶6 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol9 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路10 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide10 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter10 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸11 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
Live0000012 小时前
在鸿蒙中使用 Repeat 渲染嵌套列表,修改内层列表的一个元素,页面不会更新
前端·javascript·react native
柳杉12 小时前
使用Ai从零开发智慧水利态势感知大屏(开源)
前端·javascript·数据可视化