Title

useTitle

Reactive document title.

Usage

import { useTitle } from '@vueuse/core'

const title = useTitle()
console.log(title.value) // print current title
title.value = 'Hello' // change current title

Set initial title immediately

const title = useTitle('New Title')

Pass a ref and the title will be updated when the source ref changes

import { useTitle } from '@vueuse/core'

const messages = ref(0)

const title = computed(() => {
  return !messages.value ? 'No message' : `${messages.value} new messages`
})

useTitle(title) // document title will match with the ref "title"

Type Declarations

/**
 * Reactive document title.
 *
 * @see   {@link /useTitle}
 * @param newTitle
 * @param options
 */
export declare function useTitle(
  newTitle?: MaybeRef<string | null | undefined>,
  { document }?: ConfigurableDocument
): Ref<string | null | undefined>

Source

SourceDemoDocs