fn
useTitle
v0.0.15testeddemoReactive `document.title`. Pass a getter to derive the title from other reactive state (returns a read-only ref), or a plain value/ref for two-way binding.
Examples
ts
const title = useTitle();
title.value = 'New title';ts
useTitle('Dashboard', { titleTemplate: '%s | My App' });ts
// Derive from reactive state (read-only result)
useTitle(() => `Inbox (${count.value})`);ts
// Restore the previous title when the component unmounts
useTitle('Checkout', { restoreOnUnmount: (original) => original });Demo
Loading demo…
Signatures
ts
export function useTitle(
newTitle: () => string | null | undefined,
options?: UseTitleOptions,
): ComputedRef<string | null | undefined>;ts
export function useTitle(
newTitle?: MaybeRef<string | null | undefined>,
options?: UseTitleOptions,
): Ref<string | null | undefined>;Parameters
| Parameter | Type | Description |
|---|---|---|
newTitle? | MaybeRefOrGetter<string | null | undefined> | Initial title (getter source returns a read-only ref) |
options? | UseTitleOptionsBase | Options |
Returns
UseTitleReturnA ref bound to the document title (read-only when a getter source is passed)