You can pass content to the modal's slots using three different methods:
1. Using a String (HTML)
Pass a string of HTML to the default slot.
Warning: Use this only with trusted content to avoid XSS attacks.
const modalInstance = useModal({
component: VueFinalModal,
slots: {
default: '<p>The content of the modal</p>'
}
})
2. Using a Component
Pass a Vue component directly to the slot. This component will be rendered without any props or events passed to it.
import ModalContent from './ModalContent.vue'
const modalInstance = useModal({
component: VueFinalModal,
slots: {
default: ModalContent
}
})
3. Using useModalSlot() for Components with Props and Events
To pass props and events to a component inside a slot, use the useModalSlot() helper. This provides better TypeScript DX.
import { VueFinalModal, useModal, useModalSlot } from 'vue-final-modal'
import ModalContent from './ModalContent.vue'
const modalInstance = useModal({
component: VueFinalModal,
slots: {
default: useModalSlot({
component: ModalContent,
attrs: {
title: 'Hello world!',
onConfirm() { /* handle confirm */ }
}
})
}
})
import { VueFinalModal, useModal, useModalSlot } from 'vue-final-modal'
import ModalContent from './ModalContent.vue'
const modalInstance = useModal({
component: VueFinalModal,
slots: {
default: useModalSlot({
component: ModalContent,
attrs: {
title: 'Hello world!',
onConfirm() { }
}
})
}
})