Skip to content

Instantly share code, notes, and snippets.

@jannunen
Created September 4, 2022 10:02
Show Gist options
  • Save jannunen/33833aaf6c19b22961f1473341b081a0 to your computer and use it in GitHub Desktop.
Save jannunen/33833aaf6c19b22961f1473341b081a0 to your computer and use it in GitHub Desktop.
How to create Popover component (Vue3, script setup and BS5)
<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>
@jannunen
Copy link
Author

jannunen commented Sep 4, 2022

Usage:

import Popover from '@/components/Popover.vue'
<popover title="My title" content="My content"><button>Click</button></popover>

@idefixcert
Copy link

I tested it but in my case ele is always null.

@jannunen
Copy link
Author

Can you provide a fiddle?

@idefixcert
Copy link

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