Skip to content

Commit 9e937c0

Browse files
committed
suppot API
1 parent 3045614 commit 9e937c0

File tree

11 files changed

+424
-247
lines changed

11 files changed

+424
-247
lines changed

README.md

Lines changed: 105 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,41 +77,25 @@ Yarn:
7777
yarn add vue-final-modal
7878
```
7979

80-
## Basic usage
81-
82-
### Register
80+
## Registeration
8381

84-
#### Vue
85-
86-
- **Register in SFC**
82+
### Vue
8783

8884
```js
89-
import { VueFinalModal } from 'vue-final-modal'
85+
import VueFinalModal from 'vue-final-modal'
9086

91-
export default {
92-
components: {
93-
VueFinalModal
94-
}
95-
}
87+
Vue.use(VueFinalModal)
9688
```
9789

98-
- **Install globally**
99-
100-
```js
101-
import { VueFinalModal } from 'vue-final-modal'
102-
103-
Vue.component('VueFinalModal', VueFinalModal)
104-
```
105-
106-
#### Nuxt
90+
### Nuxt
10791

10892
- **Write a plugin `vue-final-modal.js`**
10993

11094
```js
11195
// plugins/vue-final-modal.js
112-
import VueFinalModal from 'vue-final-modal/lib/VueFinalModal.vue'
96+
import VueFinalModal from 'vue-final-modal/lib'
11397

114-
Vue.component('VueFinalModal', VueFinalModal)
98+
Vue.use(VueFinalModal)
11599
```
116100

117101
- **Add plugin into `nuxt.config.js`**
@@ -123,7 +107,7 @@ export default {
123107
}
124108
```
125109

126-
#### CDN
110+
### CDN
127111

128112
- **jsDelivr**
129113

@@ -137,21 +121,114 @@ export default {
137121
<script src="https://unpkg.com/vue-final-modal"></script>
138122
```
139123

140-
### **Add component to template**
124+
## Basic usage
125+
126+
### **Click button to open modal**
141127

142128
```html
143129
<vue-final-modal v-model="showModal">
144130
Modal Content Here
145131
</vue-final-modal>
132+
133+
<button @click="showModal = true">Launch</button>
146134
```
147135

148-
### **Create a button**
136+
### **Open modal by `name`**
149137

150138
```html
151-
<button @click="showModal = true">Launch</button>
139+
<vue-final-modal v-model="showModal" name="example">
140+
Modal Content Here
141+
</vue-final-modal>
142+
```
143+
144+
```js
145+
this.$vfm.show('example')
146+
```
147+
148+
## **API**
149+
150+
Plugin API can be called within any component through `this.$vfm`
151+
152+
### `$vfm.openedModals`
153+
154+
- Type: `Array`
155+
156+
A stack array store the opened modal's vue component instance.
157+
158+
You can use:
159+
1. `$vfm.openedModals[0]` to get the first opened modal instance.
160+
2. `$vfm.openedModals.length` to get how many modals is opened.
161+
162+
### `$vfm.modals`
163+
164+
- Type: `Array`
165+
166+
All modal instances include show and hide.
167+
168+
### `$vfm.show(name)`
169+
170+
- Type: `Function`
171+
- Arguments:
172+
- name: `String` - Name of the modal
173+
- Example:
174+
175+
```html
176+
<template>
177+
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
178+
</template>
179+
180+
<script>
181+
export default {
182+
name: 'MyComponent',
183+
data: () => ({
184+
show: false
185+
}),
186+
mounted () {
187+
this.$modal.show('example')
188+
}
189+
}
190+
</script>
152191
```
153192

154-
### **Default props**
193+
### `$vfm.hide(name)`
194+
195+
- Type: `Function`
196+
- Arguments:
197+
- name: `String` - Name of the modal
198+
- Example:
199+
200+
```html
201+
<template>
202+
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
203+
</template>
204+
205+
<script>
206+
export default {
207+
name: 'MyComponent',
208+
data: () => ({
209+
show: true
210+
}),
211+
mounted () {
212+
this.$modal.hide('example')
213+
}
214+
}
215+
</script>
216+
```
217+
218+
### `$vfm.hideAll()`
219+
220+
hide all modals.
221+
222+
### `$vfm.toggle(name, show)`
223+
224+
- Type: `Function`
225+
- Arguments:
226+
- name: `String` - Name of the modal
227+
- show: `Boolean` - Show modal or not
228+
229+
toggle modal by name.
230+
231+
## **Props**
155232

156233
```js
157234
const CLASS_TYPES = [String, Object, Array]

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)