File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
packages/vue-final-modal/src Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export type ModalSlot = string | Component | ModalSlotOptions
24
24
25
25
export type UseModalOptions < P > = {
26
26
defaultModelValue ?: boolean
27
+ keepModalInstance ?: boolean
27
28
context ?: Vfm
28
29
component ?: Constructor < P >
29
30
attrs ?: ( RawProps & P ) | ( { } extends P ? null : never )
Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
69
69
console . warn ( '[Vue Final Modal warn] useModal() can only be used inside setup() or functional components.' )
70
70
}
71
71
72
+ tryOnUnmounted ( ( ) => {
73
+ if ( ! options . keepModalInstance )
74
+ destroy ( )
75
+ } )
76
+
72
77
function open ( ) : Promise < string > {
73
78
if ( options . modelValue )
74
79
return Promise . resolve ( '[Vue Final Modal] modal is already opened' )
@@ -86,7 +91,12 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
86
91
87
92
options . modelValue = false
88
93
return new Promise ( ( resolve ) => {
89
- options . resolveClosed = ( ) => resolve ( 'closed' )
94
+ options . resolveClosed = ( ) => {
95
+ console . log ( `close options.keepModalInstance → ` , options . keepModalInstance )
96
+ if ( ! options . keepModalInstance )
97
+ destroy ( )
98
+ resolve ( 'closed' )
99
+ }
90
100
} )
91
101
}
92
102
@@ -118,17 +128,13 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
118
128
options . context . dynamicModals . splice ( index , 1 )
119
129
}
120
130
121
- const modal = {
131
+ return {
122
132
options,
123
133
open,
124
134
close,
125
135
patchOptions,
126
136
destroy,
127
137
}
128
-
129
- tryOnUnmounted ( ( ) => modal . destroy ( ) )
130
-
131
- return modal
132
138
}
133
139
134
140
export function useModalSlot < P > ( options : {
You can’t perform that action at this time.
0 commit comments