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" />
相关推荐
尘世中一位迷途小书童1 天前
用 Cesium 撸了一个森林火情监控大屏,弧线、粒子、发光效果都齐了
前端·javascript
IT_陈寒1 天前
垃圾回收器选错了,我的Java服务内存炸了
前端·人工智能·后端
月光下的丝瓜1 天前
Flutter 国内安装指南
前端·flutter
先吃饱再说1 天前
JavaScript中`this` 的“千层套路”:从默认绑定到箭头函数的五种指向
javascript
玄星啊1 天前
AI 编程的第 30 天,我怀念古法 Coding 了
前端·ai编程
Jolyne_1 天前
Angular基础速通
前端·angular.js
foxire1 天前
基于nodejs实现服务端内核引擎
javascript
锋行天下1 天前
半秒开!还有谁!!!
前端·vue.js·架构
代码搬运媛1 天前
git 下中文文件名乱码问题解决
前端
CaffeinePro1 天前
告别知识点零散!React零基础通关,从环境搭建到Ant Design页面实战
前端·react.js