Created
September 4, 2022 10:02
-
-
Save jannunen/33833aaf6c19b22961f1473341b081a0 to your computer and use it in GitHub Desktop.
How to create Popover component (Vue3, script setup and BS5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<slot /> | |
</template> | |
<script setup> | |
import { Popover } from 'bootstrap' | |
import { onMounted } from 'vue' | |
import { useSlots } from 'vue'; | |
const slots = useSlots(); | |
const props = defineProps({ | |
content: { | |
required: false, | |
default: '', | |
}, | |
title: { | |
default: 'My Popover', | |
}, | |
trigger: { | |
default: 'hover', | |
}, | |
delay: { | |
default: 0, | |
}, | |
html: { | |
default: false, | |
}, | |
}) | |
onMounted(() => { | |
const ele = slots.default()[0].el | |
new Popover(ele, props) | |
}) | |
</script> |
I tested it but in my case ele is always null.
Can you provide a fiddle?
I am not an expert in vue (just starting)
here the fiddle:
https://codesandbox.io/s/vue-composition-api-example-forked-dnnxig?file=/src/App.vue
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: