mirror of
https://github.com/KevinMidboe/vue-js-modal.git
synced 2025-10-29 09:50:22 +00:00
#178 Close dynamic modals programmatically
This commit is contained in:
13
README.md
13
README.md
@@ -177,6 +177,19 @@ this.$modal.show(MyComponent, {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Other than defining the `name` modal parameter, it's also possible to close dynamic modals emitting a `'close'` event:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
this.$modal.show({
|
||||||
|
template: `
|
||||||
|
<div>
|
||||||
|
<p>Close using this button:</p>
|
||||||
|
<button @click="$emit('close')">Close</button>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
For more examples please take a look at [vue-js-modal.yev.io](http://vue-js-modal.yev.io).
|
For more examples please take a look at [vue-js-modal.yev.io](http://vue-js-modal.yev.io).
|
||||||
|
|
||||||
### SSR
|
### SSR
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ export default {
|
|||||||
showDynamicRuntimeModal () {
|
showDynamicRuntimeModal () {
|
||||||
this.$modal.show({
|
this.$modal.show({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div class="example-modal-content">
|
||||||
<h1>This is created inline</h1>
|
<h1>This is created inline</h1>
|
||||||
<p>{{ text }}</p>
|
<p>{{ text }}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -243,9 +243,19 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
showDynamicComponentModalWithModalParams () {
|
showDynamicComponentModalWithModalParams () {
|
||||||
this.$modal.show(CustomComponentModal, {
|
this.$modal.show({
|
||||||
text: 'This text is passed as a property'
|
template: `
|
||||||
}, {
|
<div class="example-modal-content">
|
||||||
|
<button class="btn" @click="closeByName">Close this using name</button>
|
||||||
|
<button class="btn" @click="closeByEvent">Close this using events</button>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
methods: {
|
||||||
|
closeByName() { this.$modal.hide('dynamic-modal'); },
|
||||||
|
closeByEvent() { this.$emit('close'); },
|
||||||
|
}
|
||||||
|
}, null, {
|
||||||
|
name: 'dynamic-modal',
|
||||||
resizable: true,
|
resizable: true,
|
||||||
adaptive: true,
|
adaptive: true,
|
||||||
draggable: true,
|
draggable: true,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="example-modal-content">
|
||||||
<h1>This is a custom component</h1>
|
<h1>This is a custom component</h1>
|
||||||
<p>{{ text }}</p>
|
<p>{{ text }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
<modal
|
<modal
|
||||||
v-for="modal in modals"
|
v-for="modal in modals"
|
||||||
:key="modal.id"
|
:key="modal.id"
|
||||||
:name="modal.name"
|
|
||||||
v-bind="modal.config"
|
v-bind="modal.config"
|
||||||
@closed="remove(modal.id)"
|
@closed="remove(modal.id)"
|
||||||
>
|
>
|
||||||
<component :is="modal.component" v-bind="modal.params"></component>
|
<component
|
||||||
|
:is="modal.component"
|
||||||
|
v-bind="modal.params"
|
||||||
|
@close="$modal.hide(modal.config.name)"
|
||||||
|
></component>
|
||||||
</modal>
|
</modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -25,16 +28,18 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
add (modal, params, config) {
|
add (modal, params, config) {
|
||||||
let id = this.uid++
|
let id = this.uid++
|
||||||
let name = '_dynamic-modal-' + id
|
config = config || {};
|
||||||
|
if (!config.name) {
|
||||||
|
config.name = '_dynamic-modal-' + id;
|
||||||
|
}
|
||||||
this.modals.push({
|
this.modals.push({
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
|
||||||
component: modal,
|
component: modal,
|
||||||
params: params || {},
|
params: params || {},
|
||||||
config: config || {}
|
config: config || {}
|
||||||
})
|
})
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$modal.show(name)
|
this.$modal.show(config.name)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
remove (id) {
|
remove (id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user