Looking for a Vue 3 version? It’s over here
Vue Final Modal
is a renderless component
You can create a higher-order component easily and can customize template
, script
and style
based on your needs.
features:
Vue 3.0
NPM:
npm install vue-final-modal@next --save
Yarn:
yarn add vue-final-modal@next
Vue 2.0
NPM:
npm install vue-final-modal --save
Yarn:
yarn add vue-final-modal
import VueFinalModal from 'vue-final-modal'
Vue.use(VueFinalModal)
vue-final-modal.js
// plugins/vue-final-modal.js
import VueFinalModal from 'vue-final-modal/lib'
Vue.use(VueFinalModal)
nuxt.config.js
// nuxt.config.js
export default {
plugins: ['~plugins/vue-final-modal.js']
}
<script src="https://cdn.jsdelivr.net/npm/vue-final-modal"></script>
<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')
Plugin API can be called within any component through this.$vfm
.
$vfm.openedModals
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.length
to get how many modals is opened.$vfm.modals
Array
All modal instances include show and hide.
$vfm.show(name)
Function
String
- Name of the modal<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>
$vfm.hide(name)
Function
String
- Name of the modal<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>
$vfm.hideAll()
hide all modals.
$vfm.toggle(name, show)
Function
String
- Name of the modalBoolean
- Show modal or nottoggle modal by name.
const CLASS_TYPES = [String, Object, Array]
{
value: { type: Boolean, default: false },
ssr: { type: Boolean, default: true },
classes: { type: CLASS_TYPES, default: '' },
overlayClass: { type: CLASS_TYPES, default: '' },
contentClass: { type: CLASS_TYPES, default: '' },
lockScroll: { type: Boolean, default: true },
hideOverlay: { type: Boolean, default: false },
clickToClose: { type: Boolean, default: true },
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 },
focusTrap: { type: Boolean, default: false }
}
@click-outside
If prop
clickToClose
isfalse
, the event will still be emitted.
@before-open
@opened
@before-close
@closed
If you have any ideas for optimization of vue-final-modal
, feel free to open issues or pull requests.
Author: hunterliu1003
Demo: https://vue-final-modal.org/
Source Code: https://github.com/hunterliu1003/vue-final-modal
#vuejs #vue #javascript