Hey I'm not at home in vue 3 and element plus. But I'm wondering if you could close the dialog using a template ref.
But what would happen if you try this?
1 . Add a ref="modal" to the el-dialog component
-
Define the ref()
-
Close the dialog through the ref after the call
<template>
<el-dialog
<!-- add a template ref to the dialog component -->
ref="modal"
v-model="dialogVisible"
title="Tips"
width="30%"
:before-close="handleClose"
>
<span>This is a message</span>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">Cancel</el-button>
<el-button type="primary" @click="dialogVisible = false">
Confirm
</el-button>
</span>
<button @click="test">Hello</button>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
const dialogVisible = ref(false)
// Define the template ref
const modal = ref(null)
// Close the modal through the template ref
const closeTroughRef = () => {
modal.value.visible = false
}
// After handling the request call closeTroughRef()
</script>