Skip to content
On this page

useFavicon

Category
Last Changed
3 months ago

Reactive favicon

Demo

Change favicon to

Usage



 








import { useFavicon } from '@vueuse/core'

const icon = useFavicon()

icon.value = 'dark.png' // change current icon
import { useFavicon } from '@vueuse/core'

const icon = useFavicon()

icon.value = 'dark.png' // change current icon

Passing a source ref

You can pass a ref to it, changes from of the source ref will be reflected to your favicon automatically.







 








import { computed } from 'vue'
import { useFavicon, usePreferredDark } from '@vueuse/core'

const isDark = usePreferredDark()
const favicon = computed(() => isDark.value ? 'dark.png' : 'light.png')

useFavicon(favicon)
import { computed } from 'vue'
import { useFavicon, usePreferredDark } from '@vueuse/core'

const isDark = usePreferredDark()
const favicon = computed(() => isDark.value ? 'dark.png' : 'light.png')

useFavicon(favicon)

When a source ref is passed, the return ref will be identical to the source ref

const source = ref('icon.png')
const icon = useFavicon(source)

console.log(icon === source) // true
const source = ref('icon.png')
const icon = useFavicon(source)

console.log(icon === source) // true

Type Declarations

export interface FaviconOptions extends ConfigurableDocument {
  baseUrl?: string
  rel?: string
}
/**
 * Reactive favicon.
 *
 * @see https://vueuse.org/useFavicon
 * @param newIcon
 * @param options
 */
export declare function useFavicon(
  newIcon?: MaybeRef<string | null | undefined>,
  options?: FaviconOptions
): Ref<string | null | undefined>
export interface FaviconOptions extends ConfigurableDocument {
  baseUrl?: string
  rel?: string
}
/**
 * Reactive favicon.
 *
 * @see https://vueuse.org/useFavicon
 * @param newIcon
 * @param options
 */
export declare function useFavicon(
  newIcon?: MaybeRef<string | null | undefined>,
  options?: FaviconOptions
): Ref<string | null | undefined>

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
Alex Kozack

Changelog

No recent changes
useFavicon has loaded