fix modal

This commit is contained in:
2024-07-02 07:53:42 +02:00
parent c1c6f46255
commit 2ffa793e84

View File

@@ -20,16 +20,16 @@ import { onMounted, onBeforeUnmount, ref, watch } from 'vue'
export default { export default {
props: ['modelValue', 'title', 'class_other'], props: ['modelValue', 'title', 'class_other'],
emits: ['change','update:modelValue'], emits: ['change','update:modelValue','hide'],
setup(props, { emit }) { setup(props, { emit }) {
const id = 'modal' + Math.round(Math.random() * 100000) const id = 'modal' + Math.round(Math.random() * 100000)
const modal = ref(null) const modal = ref(null)
const triggerModal = (value, emitEvent = true) => { const triggerModal = (value, emitEvent = true) => {
if (value == true) { if (value == true) {
modal.modelValue.show() modal.value.show()
} else { } else {
modal.modelValue.hide() modal.value.hide()
if (emitEvent) { if (emitEvent) {
emit('hide') emit('hide')
} }
@@ -39,7 +39,7 @@ export default {
onMounted(() => { onMounted(() => {
document.body.append(document.getElementById(id)) document.body.append(document.getElementById(id))
modal.modelValue = new Modal(document.getElementById(id)) modal.value = new Modal(document.getElementById(id))
document.getElementById(id).addEventListener('hidden.bs.modal', function () { document.getElementById(id).addEventListener('hidden.bs.modal', function () {
triggerModal(false) triggerModal(false)
}) })
@@ -47,7 +47,7 @@ export default {
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
modal.modelValue.hide() modal.value.hide()
setTimeout(function () { setTimeout(function () {
document.getElementById(id).remove() document.getElementById(id).remove()
}, 500) }, 500)