Looking for a Vue 3 version? It's over here
🎉 Documentation
🙌 Examples
You can create a higher-order component easily and can customize template, script and style based on your needs.
features:
- Support Vue 3 and Vue 2
- Tailwind CSS friendly
- Renderless component
- SSR support
- Stackable
- Detachable
- Scrollable
- Transition support
- Mobile friendly
- Tiny bundle size
- Accessibility support
Vue 3.0
NPM:
npm install vue-final-modal@next --saveYarn:
yarn add vue-final-modal@nextVue 2.0
NPM:
npm install vue-final-modal --saveYarn:
yarn add vue-final-modalimport VueFinalModal from 'vue-final-modal'
Vue.use(VueFinalModal())- Write a plugin
vue-final-modal.js
// plugins/vue-final-modal.js
import VueFinalModal from 'vue-final-modal/lib'
Vue.use(VueFinalModal())- Add plugin into
nuxt.config.js
// nuxt.config.js
export default {
plugins: [
{ src: '~plugins/vue-final-modal.js' }
],
build: {
transpile: ['vue-final-modal']
}
}- jsDelivr
<script src="https://cdn.jsdelivr.net/npm/vue-final-modal"></script>- Unpkg
<script src="https://unpkg.com/vue-final-modal"></script><vue-final-modal v-model="showModal">
Modal Content Here
</vue-final-modal>
<button @click="showModal = true">Launch</button><vue-final-modal v-model="showModal" name="example">
Modal Content Here
</vue-final-modal>this.$vfm.show('example')Only work in v0.18+
Configuration options can be passed as a second argument to Vue.use.
import VueFinalModal from 'vue-final-modal'
Vue.use(VueFinalModal(), { ... })- Type:
String - default:
'VueFinalModal'
Changes component name from "VueFinalModal" to any other string value. It is useful when there is already a global "modal" component.
- Type:
String - default:
'$vfm'
Changes API name from "$vfm" to any other string value. It is useful when you use vue-final-modal as spinner, toast, notify, etc.
Plugin API can be called within any component through this.$vfm.
- Type:
Array
A stack array store the opened modal's vue component instance.
You can use:
$vfm.openedModals[0]to get the first opened modal instance.$vfm.openedModals.lengthto get how many modals is opened.
- Type:
Array
All modal instances include show and hide.
- Type:
Function - Arguments:
- name:
String- Name of the modal
- name:
- Example:
<template>
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
</template>
<script>
export default {
name: 'MyComponent',
data: () => ({
show: false
}),
mounted () {
this.$vfm.show('example')
}
}
</script>- Type:
Function - Arguments:
- name:
String- Name of the modal
- name:
- Example:
<template>
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
</template>
<script>
export default {
name: 'MyComponent',
data: () => ({
show: true
}),
mounted () {
this.$vfm.hide('example')
}
}
</script>hide all modals.
- Type:
Function - Arguments:
- name:
String- Name of the modal - show:
Boolean- Show modal or not
- name:
toggle modal by name.
{
value: { type: Boolean, default: false },
ssr: { type: Boolean, default: true },
classes: { type: [String, Object, Array], default: '' },
overlayClass: { type: [String, Object, Array], default: '' },
contentClass: { type: [String, Object, Array], default: '' },
styles: { type: [String, Object, Array], default: '' },
overlayStyle: { type: [String, Object, Array], default: '' },
contentStyle: { type: [String, Object, Array], default: '' },
lockScroll: { type: Boolean, default: true },
hideOverlay: { type: Boolean, default: false },
clickToClose: { type: Boolean, default: true },
escToClose: { type: Boolean, default: false },
preventClick: { type: Boolean, default: false },
attach: { type: null, default: false, validator: validateAttachTarget },
transition: { type: String, default: 'vfm' },
overlayTransition: { type: String, default: 'vfm' },
zIndexBase: { type: [String, Number], default: 1000 },
zIndex: { type: [Boolean, String, Number], default: false },
focusRetain: { type: Boolean, default: true },
focusTrap: { type: Boolean, default: false }
}- Emits while modal container on click.
If prop
clickToCloseisfalse, the event will still be emitted.
- Emits while modal is still invisible, but before transition starting.
- Emits after modal became visible and transition ended.
- Emits before modal is going to be closed.
- Emits right before modal is destroyed.
đź‘‹ Hi I'm Hunter, the author of vue-final-modal.
To develop vue-final-modal, I learn a lot from these awesome libraries:
- Vuetify
- attach
- Element UI
- stackable modal
- zIndex
- zIndexBase
- vue-js-modal
- dynamic modal
- transition
- focusTrap for A11y
- Bootstrap Vue
- lockScroll
There is no perfect library even the
finalof vue modal.
If you have any ideas for optimization of vue-final-modal, feel free to open issues or pull requests.
