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
2424
2525export type UseModalOptions < P > = {
2626 defaultModelValue ?: boolean
27+ keepModalInstance ?: boolean
2728 context ?: Vfm
2829 component ?: Constructor < P >
2930 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
6969 console . warn ( '[Vue Final Modal warn] useModal() can only be used inside setup() or functional components.' )
7070 }
7171
72+ tryOnUnmounted ( ( ) => {
73+ if ( ! options . keepModalInstance )
74+ destroy ( )
75+ } )
76+
7277 function open ( ) : Promise < string > {
7378 if ( options . modelValue )
7479 return Promise . resolve ( '[Vue Final Modal] modal is already opened' )
@@ -86,7 +91,12 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
8691
8792 options . modelValue = false
8893 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+ }
90100 } )
91101 }
92102
@@ -118,17 +128,13 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
118128 options . context . dynamicModals . splice ( index , 1 )
119129 }
120130
121- const modal = {
131+ return {
122132 options,
123133 open,
124134 close,
125135 patchOptions,
126136 destroy,
127137 }
128-
129- tryOnUnmounted ( ( ) => modal . destroy ( ) )
130-
131- return modal
132138}
133139
134140export function useModalSlot < P > ( options : {
You can’t perform that action at this time.
0 commit comments