Skip to content

Commit e2ffc79

Browse files
committed
feat: support get API
1 parent ecc0649 commit e2ffc79

File tree

7 files changed

+39
-27
lines changed

7 files changed

+39
-27
lines changed

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.

docs/content/en/index.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,6 @@ Changes API name from "$vfm" to any other string value. It is useful when you us
194194

195195
Plugin API can be called within any component through `this.$vfm`.
196196

197-
### `$vfm.openedModals`
198-
199-
- Type: `Array`
200-
201-
A stack array store the opened modal's vue component instance.
202-
203-
You can use:
204-
1. `$vfm.openedModals[0]` to get the first opened modal instance.
205-
2. `$vfm.openedModals.length` to get how many modals is opened.
206-
207-
### `$vfm.modals`
208-
209-
- Type: `Array`
210-
211-
All modal instances include show and hide.
212-
213197
### `$vfm.show(name, params)`
214198

215199
- Type: `Function`
@@ -308,6 +292,30 @@ Or get `params` on `@beforeOpen` event:
308292
309293
toggle modal by name.
310294

295+
### `$vfm.get(name)`
296+
297+
- Type: `Function`
298+
- Arguments:
299+
- name: `String` - Name of the modal
300+
301+
return the modal comopnent instance.
302+
303+
### `$vfm.openedModals`
304+
305+
- Type: `Array`
306+
307+
A stack array store the opened modal's vue component instance.
308+
309+
You can use:
310+
1. `$vfm.openedModals[0]` to get the first opened modal instance.
311+
2. `$vfm.openedModals.length` to get how many modals is opened.
312+
313+
### `$vfm.modals`
314+
315+
- Type: `Array`
316+
317+
All modal instances include show and hide.
318+
311319
## **Props**
312320

313321
### `ssr`

lib/PluginCore.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ function createVfm(options) {
66

77
return function() {
88
vfm = {
9-
isScrollLocked: false,
10-
get openedModals() {
11-
return this.modals.filter(modal => modal.value)
12-
},
13-
modals: [],
149
show(name, ...args) {
1510
this.toggle(name, true, ...args)
1611
},
@@ -23,11 +18,12 @@ function createVfm(options) {
2318
})
2419
},
2520
toggle(name, ...args) {
26-
const modal = this.modals.find(modal => modal.name === name)
21+
const modal = this.get(name)
2722
if (modal !== undefined) {
2823
modal.toggle(...args)
2924
}
3025
},
26+
isScrollLocked: false,
3127
lockScroll() {
3228
if (this.isScrollLocked) return
3329
if (options.isMobile) {
@@ -47,7 +43,14 @@ function createVfm(options) {
4743
},
4844
lockScrollListener(e) {
4945
e.preventDefault()
50-
}
46+
},
47+
get(name) {
48+
return this.modals.find(modal => modal.name === name)
49+
},
50+
get openedModals() {
51+
return this.modals.filter(modal => modal.value)
52+
},
53+
modals: []
5154
}
5255
return vfm
5356
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare module 'vue/types/vue' {
1212
readonly $vfm: {
1313
readonly openedModals: VueFinalModalComponant[]
1414
readonly modals: VueFinalModalComponant[]
15+
get(name: string): VueFinalModalComponant | undefined
1516
show(name: string): void
1617
hide(name: string): void
1718
hideAll(): void

0 commit comments

Comments
 (0)