diff --git a/README.md b/README.md index c767b0d..7ff0730 100644 --- a/README.md +++ b/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: ` +
+

Close using this button:

+ +
+ ` +}) +``` + For more examples please take a look at [vue-js-modal.yev.io](http://vue-js-modal.yev.io). ### SSR diff --git a/demo/client_side_rendering/src/App.vue b/demo/client_side_rendering/src/App.vue index b49fcc5..74dec9d 100644 --- a/demo/client_side_rendering/src/App.vue +++ b/demo/client_side_rendering/src/App.vue @@ -225,7 +225,7 @@ export default { showDynamicRuntimeModal () { this.$modal.show({ template: ` -
+

This is created inline

{{ text }}

@@ -243,9 +243,19 @@ export default { }, showDynamicComponentModalWithModalParams () { - this.$modal.show(CustomComponentModal, { - text: 'This text is passed as a property' - }, { + this.$modal.show({ + template: ` +
+ + +
+ `, + methods: { + closeByName() { this.$modal.hide('dynamic-modal'); }, + closeByEvent() { this.$emit('close'); }, + } + }, null, { + name: 'dynamic-modal', resizable: true, adaptive: true, draggable: true, diff --git a/demo/client_side_rendering/src/components/CustomComponentModal.vue b/demo/client_side_rendering/src/components/CustomComponentModal.vue index ac4b322..d0c3d11 100644 --- a/demo/client_side_rendering/src/components/CustomComponentModal.vue +++ b/demo/client_side_rendering/src/components/CustomComponentModal.vue @@ -1,5 +1,5 @@ @@ -25,16 +28,18 @@ export default { methods: { add (modal, params, config) { let id = this.uid++ - let name = '_dynamic-modal-' + id + config = config || {}; + if (!config.name) { + config.name = '_dynamic-modal-' + id; + } this.modals.push({ id: id, - name: name, component: modal, params: params || {}, config: config || {} }) this.$nextTick(() => { - this.$modal.show(name) + this.$modal.show(config.name) }) }, remove (id) {