Jenesius Vue Modal
Jenesius vue modal is simple library for Vue 3 only .
Installation
npm i jenesius-vue-modal
For add modals in your project you need to put the modal's container in the App component:
App.vue
<template>
<widget-container-modal />
</template>
<script>
import {container} from "jenesius-vue-modal";
export default {
components: {WidgetContainerModal: container},
name: "App"
}
</script>
OpenModal
Methods openModal
and pushModal
used to display modal windows.
openModal
- close all previous modals and then display provided component.pushModal
- display provided component
import {openModal} from "jenesius-vue-modal";
import SomeVueComponent from "SomeVueComponent.vue";
openModal(SomeVueComponent, props);
- props will provide in your component, example
Methods return promise, in this case promise is resolved - modalObject
const modal = await openModal(SomeVueComponent);
Methods
openModal
- close all modals and then open provided modal.pushModal
- add one more provided modal.closeModal
- close all modals.popModal
- close last opened modal.
Lifecycle Hooks
There are three ways to track the closing of a modal:
Versions is higher than 1.2.0 NOT support 'next'. Now All hooks use only returned value(Boolean) for navigation hooks.
If function return false or throwing an Error modal window will not be closed.
const modal = await openModal(Modal);
modal.onclose = () => {
console.log("Close");
return false;
}
export default {
props: {},
data: () => ({isValidate: false}),
beforeModalClose(){
console.log("Close");
if (!isValidate) return false;
}
}
export default{
setup() {
onBeforeModalClose(() => {
console.log("Close");
});
}
}
Async/Await
Hooks also can be asynchronous functions:
async beforeModalClose(){
await doSome();
return false;
}
or
beforeModalClose(){
return Promise(resolve => {
setTimeout(() => resolve(true), 2000);
})
}
Example VueModalComponent
WidgeTestModal.vue
<template>
<p>{{title}}</p>
</template>
<script>
export default {
props: {
title: String
}
}
</script>
To show this component
import {openModal} from "jenesius-vue-modal"
import WidgeTestModal from "WidgeTestModal.vue";
openModal(WidgeTestModal, {
title: "Hello World!"
});
Do you like this module? Put a star on GitHub