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" />
相关推荐
u***u6852 小时前
React环境
前端·react.js·前端框架
X***E4632 小时前
前端数据分析应用
前端·数据挖掘·数据分析
4***14902 小时前
React社区
前端·react.js·前端框架
LFly_ice2 小时前
学习React-24-路由传参
前端·学习·react.js
Lhuu(重开版3 小时前
CSS:动效布局动画
前端·css
Q***K553 小时前
前端构建工具
前端
laocooon5238578863 小时前
创建了一个带悬停效果的“我的个人主页“按钮
前端
2013编程爱好者4 小时前
Vue工程结构分析
前端·javascript·vue.js·typescript·前端框架
小满zs5 小时前
Next.js第十一章(渲染基础概念)
前端
不羁的fang少年6 小时前
前端常见问题(vue,css,html,js等)
前端·javascript·css