Skip to content

Commit 45c64f5

Browse files
committed
chore: example that use useModal outside out script setup
1 parent 16e556b commit 45c64f5

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

packages/nuxt/playground/components/PlainCssConfirmModalPreview.vue

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
<script setup lang="ts">
2-
import { ModalsContainer, useModal } from 'vue-final-modal'
3-
import PlainCssConfirmModal from './PlainCssConfirmModal.vue'
2+
import { ModalsContainer, useVfm } from 'vue-final-modal'
3+
import { showConfirmModal } from './showConfirmModal'
44
5-
const { open, close } = useModal({
6-
component: markRaw(PlainCssConfirmModal),
7-
attrs: {
8-
title: 'Hello World!',
9-
onConfirm() {
10-
close()
11-
},
12-
},
13-
slots: {
14-
default: '<p>The content of the modal</p>',
15-
},
16-
})
5+
const vfm = useVfm()
176
</script>
187

198
<template>
20-
<button @click="() => open()">
9+
<button @click="() => showConfirmModal(vfm)">
2110
Open Modal
2211
</button>
2312

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Vfm } from 'vue-final-modal'
2+
import { useModal } from 'vue-final-modal'
3+
import PlainCssConfirmModal from './PlainCssConfirmModal.vue'
4+
5+
export function showConfirmModal(vfm: Vfm) {
6+
const { open, close, destroy } = useModal({
7+
context: vfm,
8+
component: markRaw(PlainCssConfirmModal),
9+
attrs: {
10+
title: 'Hello World!',
11+
onConfirm() {
12+
close()
13+
},
14+
onClosed() {
15+
destroy()
16+
},
17+
},
18+
slots: {
19+
default: '<p>The content of the modal</p>',
20+
},
21+
})
22+
23+
open()
24+
}

0 commit comments

Comments
 (0)