Vue Header Component - Nuxt UI
Header GitHub A responsive header for your site navigation. Usage The Header component renders a <header> element. Its height is defined through a --ui-header-height CSS variable. Use the left , default and right slots to customize the header and the body or content slots to customize the header menu. < script setup lang = " ts " > import type { NavigationMenuItem } from ' @nuxt/ui ' const route = useRoute () const items = computed < NavigationMenuItem [] > ( () => [ { label : ' Docs ' , to : ' /docs/getting-started ' , active : route . path . startsWith ( ' /docs/getting-started ' ) }, { label : ' Components ' , to : ' /docs/components ' , active : route . path . startsWith ( ' /docs/components ' ) }, { label : ' Figma ' , to : ' https://go.nuxt.com/figma-ui ' , target : ' _blank ' }, { label : ' Releases ' , to : ' https://github.com/nuxt/ui/releases ' , target : ' _blank ' } ]) </ script > < template > < UHeader > < template # title > < Logo class = " h-6 w-auto " /> </ template > < UNavigationMenu : items = " items " /> < template # right > < UColorModeButton /> < UTooltip text = " Open on GitHub " : kbds = " [ ' meta ' , ' G ' ] " > < UButton color = " neutral " variant = " ghost " to = " https://github.com/nuxt/ui " target = " _blank " icon = " i-simple-icons-github " aria-label = " GitHub " /> </ UTooltip > </ template > </ UHeader > </ template > < script setup lang = " ts " > import { computed } from ' vue ' import type { NavigationMenuItem } from ' @nuxt/ui ' const route = useRoute () const items = computed < NavigationMenuItem [] > ( () => [ { label : ' Docs ' , to : ' /docs/getting-started ' , active : route . path . startsWith ( ' /docs/getting-started ' ) }, { label : ' Components ' , to : ' /docs/components ' , active : route . path . startsWith ( ' /docs/components ' ) }, { label : ' Figma ' , to : ' https://go.nuxt.com/figma-ui ' , target : ' _blank ' }, { label : ' Releases ' , to : ' https://github.com/nuxt/ui/releases ' , target : ' _blank ' } ]) </ script > < template > < UHeader > < template # title > < Logo class = " h-6 w-auto " /> </ template > < UNavigationMenu : items = " items " /> < template # right > < UColorModeButton /> < UTooltip text = " Open on GitHub " : kbds = " [ ' meta ' , ' G ' ] " > < UButton color = " neutral " variant = " ghost " to = " https://github.com/nuxt/ui " target = " _blank " icon = " i-simple-icons-github " aria-label = " GitHub " /> </ UTooltip > </ template > </ UHeader > </ template > In this example, we use the NavigationMenu component to render the header links in the center.
Title Use the title prop to change the title of the header. Defaults to Nuxt UI . title < template > < UHeader title = " Nuxt UI " /> </ template > You can also use the title slot to add your own logo. You should still add the title prop to replace the default aria-label of the link. < template > < UHeader > < template # title > < Logo class = " h-6 w-auto " /> </ template > </ UHeader > </ template > To Use the to prop to change the link of the title.
Defaults to / . to < template > < UHeader to = " /docs " /> </ template > You can also use the left slot to override the link entirely. < template > < UHeader > < template # left > < NuxtLink to = " /docs " > < Logo class = " h-6 w-auto " /> </ NuxtLink > </ template > </ UHeader > </ template > Mode Use the mode prop to change the mode of the header menu. Defaults to modal . Use the body slot to fill the menu body (under the header) or the content slot to fill the entire menu.
You can use the menu prop to customize the menu of the header, it will adapt depending on the mode you choose. mode < script setup lang = " ts " > import type { NavigationMenuItem } from ' @nuxt/ui ' const route = useRoute () const items = computed < NavigationMenuItem [] > ( () => [ { label : ' Docs ' , to : ' /docs/getting-started ' , icon : ' i-lucide-book-open ' , active : route . path . startsWith ( ' /docs/getting-started ' ) }, { label : ' Components ' , to : ' /docs/components ' , icon : ' i-lucide-box ' , active : route . path . startsWith ( ' /docs/components ' ) }, { label : ' Figma ' , icon : ' i-simple-icons-figma ' , to : ' https://go.nuxt.com/figma-ui ' , target : ' _blank ' }, { label : ' Releases ' , icon : ' i-lucide-rocket ' , to : ' https://github.com/nuxt/ui/releases ' , target : ' _blank ' } ]) </ script > < template > < UHeader > < template # title > < Logo class = " h-6 w-auto " /> </ template > < UNavigationMenu : items = " items " /> < template # right > < UColorModeButton /> < UTooltip text = " Open on GitHub " : kbds = " [ ' meta ' , ' G ' ] " > < UButton color = " neutral " variant = " ghost " to = " https://github.com/nuxt/ui " target = " _blank " icon = " i-simple-icons-github " aria-label = " GitHub " /> </ UTooltip > </ template > < template # body > < UNavigationMenu : items = " items " orientation = " vertical " class = " -mx-2.5 " /> </ template > </ UHeader > </ template > < script setup lang = " ts " > import { computed } from ' vue ' import type { NavigationMenuItem } from ' @nuxt/ui ' const route = useRoute () const items = computed < NavigationMenuItem [] > ( () => [ { label : ' Docs ' , to : ' /docs/getting-started ' , icon : ' i-lucide-book-open ' , active : route . path . startsWith ( ' /docs/getting-started ' ) }, { label : ' Components ' , to : ' /docs/components ' , icon : ' i-lucide-box ' , active : route . path . startsWith ( ' /docs/components ' ) }, { label : ' Figma ' , icon : ' i-simple-icons-figma ' , to : ' https://go.nuxt.com/figma-ui ' , target : ' _blank ' }, { label : ' Releases ' , icon : ' i-lucide-rocket ' , to : ' https://github.com/nuxt/ui/releases ' , target : ' _blank ' } ]) </ script > < template > < UHeader > < template # title > < Logo class = " h-6 w-auto " /> </ template > < UNavigationMenu : items = " items " /> < template # right > < UColorModeButton /> < UTooltip text = " Open on GitHub " : kbds = " [ ' meta ' , ' G ' ] " > < UButton color = " neutral " variant = " ghost " to = " https://github.com/nuxt/ui " target = " _blank " icon = " i-simple-icons-github " aria-label = " GitHub " /> </ UTooltip > </ template > < template # body > < UNavigationMenu : items = " items " orientation = " vertical " class = " -mx-2.5 " /> </ template > </ UHeader > </ template > Toggle Use the toggle prop to customize the toggle button displayed on mobile.
You can pass any property from the Button component to customize it. < script setup lang = " ts " > import type { NavigationMenuItem } from ' @nuxt/ui ' const route = useRoute () const items = computed < NavigationMenuItem [] > ( () => [ { label : ' Docs ' , to : ' /docs/getting-started ' , icon : ' i-lucide-book-open ' , active : route . path . startsWith ( ' /docs/getting-started ' ) }, { label : ' Components ' , to : ' /docs/components ' , icon : ' i-lucide-box ' , active : route . path . startsWith ( ' /docs/components ' ) }, { label : ' Figma ' , icon : ' i-simple-icons-figma ' , to : ' https://go.nuxt.com/figma-ui ' , target : ' _blank ' }, { label : ' Releases ' , icon : ' i-lucide-rocket ' , to : ' https://github.com/nuxt/ui/releases ' , target : ' _blank ' } ]) </ script > < template > < UHeader : toggle = " { color : ' primary ' , variant : ' subtle ' , class : ' rounded-full ' } " > < template # title > < Logo class = " h-6 w-auto " /> </ template > < UNavigationMenu : items = " items " /> < template # right > < UColorModeButton /> < UTooltip text = " Open on GitHub " : kbds = " [ ' meta ' , ' G ' ] " > < UButton color = " neutral " variant = " ghost " to = " https://github.com/nuxt/ui " target = " _blank " icon = " i-simple-icons-github " aria-label = " GitHub " /> </ UTooltip > </ template > < template # body > < UNavigationMenu : items = " items " orientation = " vertical " class = " -mx-2.5 " /> </ template > </ UHeader > </ template > < script setup lang = " ts " > import { computed } from ' vue ' import type { NavigationMenuItem } from ' @nuxt/ui ' const route = useRoute () c
The rest of this page is on the live site.