Skip to content

⬅️ Back to Table of Contents

πŸ“„ useTitle

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 2
πŸ“¦ Imports 12
🟒 Vue Composition API 1
πŸ“‘ Type Aliases 3

πŸ“š Table of Contents

πŸ› οΈ File Location:

πŸ“‚ packages/core/useTitle/index.ts

πŸ“¦ Imports

Name Source
ReadonlyRefOrGetter @vueuse/shared
ComputedRef vue
MaybeRef vue
MaybeRefOrGetter vue
Ref vue
ConfigurableDocument ../_configurable
toRef @vueuse/shared
tryOnScopeDispose @vueuse/shared
toValue vue
watch vue
defaultDocument ../_configurable
useMutationObserver ../useMutationObserver

Vue Composition API

Name Type Reactive Variables Composables
watch watch none none

Functions

useTitle(newTitle: ReadonlyRefOrGetter<string | null | und…, options: UseTitleOptions): ComputedRef<string | null | undefined>

Reactive document title.

Parameters:

  • newTitle any: No description
  • options any: No description

See: https://vueuse.org/useTitle

Tags: @description It's not SSR compatible. Your value will be applied only on client-side.

Raw JSDoc
/**
 * Reactive document title.
 *
 * @see https://vueuse.org/useTitle
 * @param newTitle
 * @param options
 * @description It's not SSR compatible. Your value will be applied only on client-side.
 */
Code
export function useTitle(
  newTitle: ReadonlyRefOrGetter<string | null | undefined>,
  options?: UseTitleOptions,
): ComputedRef<string | null | undefined>

Internal helpers

Declared inside another function in this file.

format(t: string): any

Parameters:

  • t string

Returns: any

Calls:

  • template
  • toValue(template).replace
Code
function format(t: string) {
    if (!('titleTemplate' in options))
      return t
    const template = options.titleTemplate || '%s'
    return typeof template === 'function'
      ? template(t)
      : toValue(template).replace(/%s/g, t)
  }

Type Aliases

UseTitleOptionsBase

type UseTitleOptionsBase = {
  /**
   * Restore the original title when unmounted
   * @param originTitle original title
   * @returns restored title
   */
  restoreOnUnmount?: false | ((originalTitle: string, currentTitle: string) => string | null | undefined)
} & (
  {
    /**
     * Observe `document.title` changes using MutationObserve
     * Cannot be used together with `titleTemplate` option.
     *
     * @default false
     */
    observe?: boolean
  }
  | {
    /**
     * The template string to parse the title (e.g., '%s | My Website')
     * Cannot be used together with `observe` option.
     *
     * @default '%s'
     */
    titleTemplate?: MaybeRef<string> | ((title: string) => string)
  }
);

UseTitleOptions

type UseTitleOptions = ConfigurableDocument & UseTitleOptionsBase;

UseTitleReturn

type UseTitleReturn = ComputedRef<string | null | undefined> | Ref<string | null | undefined>;

Generated by Syntax Scribe