@@ -23,35 +23,114 @@ import { ModalsContainer } from 'vue-final-modal'
23
23
24
24
## Usage
25
25
26
+ ### Passing Props and Events
27
+
26
28
``` ts
27
29
import { VueFinalModal , useModal } from ' vue-final-modal'
28
30
29
- const modalInstance = useModal ({
31
+ const { open, close, options, patchOptions } = useModal ({
32
+ // `component` is optional and the default value is `<VueFinalModal>`.
30
33
component: VueFinalModal ,
34
+ // Open the modal or not when the modal was created, the default value is `false`.
35
+ defaultModelValue: false ,
31
36
attrs: {
32
- // Props
33
- displayDirective: ' if' ,
37
+ // Bind props to the modal component (VueFinalModal in this case).
34
38
clickToClose: true ,
35
39
escToClose: true ,
36
- // Events
40
+ // Bind events to the modal component (VueFinalModal in this case).
37
41
onBeforeOpen() { /* on before open */ },
38
42
onOpened() { /* on opened */ },
39
43
onBeforeClose() { /* on before close */ },
40
44
onClosed() { /* on closed */ },
41
- },
45
+ }
46
+ })
47
+
48
+ // Open the modal
49
+ open ().then (() => { /* Do something after modal opened */ })
50
+ // Close the modal
51
+ close ().then (() => { /* Do something after modal closed */ })
52
+ // Checkout the modal options
53
+ options // the state of the dynamic modal
54
+
55
+ // Overwrite the modal options
56
+ patchOptions ({
57
+ attrs: {
58
+ // Overwrite the modal's props
59
+ clickToClose: false ,
60
+ escToClose: false ,
61
+ }
62
+ })
63
+ ```
64
+
65
+ ### Passing Slots
66
+
67
+ #### with ` String `
68
+
69
+
70
+ ``` ts
71
+ import { VueFinalModal , useModal } from ' vue-final-modal'
72
+
73
+ const modalInstance = useModal ({
74
+ component: VueFinalModal ,
75
+ attrs: { ... },
42
76
slots: {
43
77
default: ' <p>The content of the modal</p>'
44
78
}
45
79
})
80
+ ```
81
+
82
+ :: alert { type =warning }
83
+ Security Note: https://vuejs.org/api/built-in-directives.html#v-html
84
+ Dynamically rendering arbitrary HTML on your website can be very dangerousbecause it can easily lead to XSS attacks. Only use v-html on trusted content and never on user-provided content.
85
+ ::
86
+
87
+ #### with ` Component `
46
88
47
- modalInstance .open ().then (() => { /* Do something after modal opened */ })
48
- modalInstance .close ().then (() => { /* Do something after modal closed */ })
49
- modalInstance .options // the state of the dynamic modal
50
89
51
- // Overwrite the dynamic modal options
52
- modalInstance .patchOptions ({})
90
+ ``` ts
91
+ import { VueFinalModal , useModal } from ' vue-final-modal'
92
+ // ModalContent is the component you want to put into the modal content
93
+ import ModalContent from ' ./ModalContent.vue'
94
+
95
+
96
+ const modalInstance = useModal ({
97
+ component: VueFinalModal ,
98
+ attrs: { ... },
99
+ slots: {
100
+ // You can import your own component as a slot and put it to `slots.default` without binding props and events.
101
+ default: ModalContent
102
+ }
103
+ })
53
104
```
54
105
106
+ #### with ` Component ` , ` Props ` and ` Events `
107
+
108
+ ``` ts
109
+ import { VueFinalModal , useModal , useModalSlot } from ' vue-final-modal'
110
+ // ModalContent is the component you want to put into the modal content
111
+ import ModalContent from ' ./ModalContent.vue'
112
+
113
+ const modalInstance = useModal ({
114
+ component: VueFinalModal ,
115
+ attrs: { ... },
116
+ slots: {
117
+ default: useModalSlot ({
118
+ component: ModalContent ,
119
+ attrs: {
120
+ // Bind ModalContent props
121
+ title: ' Hello world!'
122
+ // Bind ModalContent events
123
+ onConfirm () { }
124
+ }
125
+ })
126
+ }
127
+ })
128
+ ```
129
+
130
+ :: alert { type =info }
131
+ ` useModalSlot() ` is a function that provides better DX for type checking. It just returns the same object you passed in.
132
+ ::
133
+
55
134
## Edge Usage
56
135
57
136
:: alert { type =danger }
0 commit comments