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" />
相关推荐
pe7er3 小时前
window管理开发环境篇 - 持续更新
前端·后端
We་ct4 小时前
LeetCode 5. 最长回文子串:DP + 中心扩展
前端·javascript·算法·leetcode·typescript
陈随易8 小时前
有生之年系列,Nodejs进程管理pm2 v7.0发布
前端·后端·程序员
冰暮流星9 小时前
javascript之事件代理/事件委托
前端
@yanyu6669 小时前
登录注册功能-明文
vue.js·springboot
陈随易10 小时前
AI时代,你还在坚持手搓文章吗
前端·后端·程序员
里欧跑得慢12 小时前
17. Flutter Hero动画实现:让界面过渡更加优雅
前端·css·flutter·web
IT_陈寒12 小时前
Vue的这个响应式陷阱,我debug了一整天才爬出来
前端·人工智能·后端
cn_mengbei13 小时前
用React Native开发OpenHarmony应用:Reanimated共享元素过渡
javascript·react native·react.js
kyriewen13 小时前
前端测试:别为了100%覆盖率而写测试,那是自欺欺人
前端·javascript·单元测试