N
Nuxt6mo ago
Rush

Flowbite not working when using nuxtlink

Hi, I am using tailwind with flowbite in my nuxt project. I installed flowbite using the instructions on their site, if I use the traditional way of loading the page everything works as it should. But when I switch the page using nuxtlink, the flowbite components that are new on the page don't work. Please help. My app.vue:
<template>
<AppHeader />
<main>
<NuxtPage />
</main>
<AppFooter />
</template>

<script setup>
import { onMounted } from 'vue'
import { initFlowbite } from 'flowbite'

onMounted(() => {
initFlowbite();
})
</script>
<template>
<AppHeader />
<main>
<NuxtPage />
</main>
<AppFooter />
</template>

<script setup>
import { onMounted } from 'vue'
import { initFlowbite } from 'flowbite'

onMounted(() => {
initFlowbite();
})
</script>
21 Replies
Rush
Rush6mo ago
I use flowbite from their site, via the html data parameter. Is that right? maybe I should init remove this script from the app and put it in each component separately? or each page
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Coton
Coton3mo ago
hey @Rush did you find a better way than putting init on each componant / page ? Thanks !
Rush
Rush3mo ago
Hi, I stopped using init completely and instead initialized each component manually, they say it's better for single page applications
Rush
Rush3mo ago
if I remember correctly, I also tried it and left it because, for example, the navbar remained open after changing the page, so I then closed it manually after changing the page
Coton
Coton3mo ago
Oh ok. So probably depending on how we are using the app So currently if you need modal on a component you import it, a tooltip on an other, you import it too inside… can you confirm @Rush ? thanks
Rush
Rush3mo ago
I didn't understand you, how to import inside? if you want to close them after switching routes, you have to manually initialize them and add that logic there e.g. add a function to nuxtlink in that modal component that will hide it
Coton
Coton3mo ago
I mean in your current workflow you are using onMounted(() => { initTooltips(); }) On a component which uses tooltip onMounted(() => { initModals(); initDropdowns(); }) In a component which uses modals + dropdowns… etc If I understand well. Regarding the issue reported by people like you : when switching page, the js didn’t work anymore
Rush
Rush3mo ago
no
Coton
Coton3mo ago
You said « initialize each component manually » By this I guess that you are using code like the one I provided
Rush
Rush3mo ago
this is how i do it
No description
Rush
Rush3mo ago
this is manually
Coton
Coton3mo ago
Ohh I am not here yet I was more on the issue where the JS is broken by navigating on the app without hard refresh Which is fixed by onMounted everywhere OR the stack overflow I put You see ? Or… doing what to do is also a way to not have the JS broken
Rush
Rush3mo ago
I see, that solves the "broken" but flowbite is designed so that after changing the page everything is loaded again, nuxt doesn't do that, you have to add the logic for it yourself
Rush
Rush3mo ago
this is what i am calling on nuxtlink click
No description
Coton
Coton3mo ago
Yep but flowbite has a documentation page for nuxt install which don’t cover that. Thats why there is few people like me asking
Rush
Rush3mo ago
I had the same
Coton
Coton3mo ago
But now I have a scenario where I need to close a modal from a js function. So I will initialize the modal in the same official way as you Until now never had the need to initialize a thing. Every tooltip, modal… work out the box with just html
Rush
Rush3mo ago
thats because of the nuxt for example in pure html or php project you dont have to do that because its not single page app
Coton
Coton3mo ago
Yep here its because the dom is re-written