Is it possible to use the Bootstrap 5 dropdown component in a Nuxt 3 app?
My attempt failed with the following error:
[nuxt] [request error] document is not defined
Thus, I tried to wrap the dropdown component in a <ClientOnly>
component but that did not help.
Anyone got a suggestion on how I can get the dropdown to work?
Here's my code: https://stackblitz.com/edit/nuxt-starter-4jphlx?file=components/Dropdown.vue
App.vue
:
<template>
<div>
<ClientOnly>
<Dropdown />
</ClientOnly>
</div>
</template>
Dropdown.vue
:
<template>
<div class="dropdown">
<button
class="btn btn-secondary dropdown-toggle"
type="button"
id="dropdownMenuButton1"
data-bs-toggle="dropdown"
aria-expanded="false"
>
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
</template>
<script setup>
import Dropdown from 'bootstrap/js/dist/dropdown.js';
</script>