Skip to content

useFavicon

Category
Export Size
441 B
Last Changed
7 months ago

Reactive favicon

Demo

Change favicon to

Usage

ts
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.

ts
import { 
useFavicon
,
usePreferredDark
} from '@vueuse/core'
import {
computed
} from 'vue'
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

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

Type Declarations

ts
export interface UseFaviconOptions extends ConfigurableDocument {
  
baseUrl
?: string
rel
?: string
} /** * Reactive favicon. * * @see https://vueuse.org/useFavicon * @param newIcon * @param options */ export declare function
useFavicon
(
newIcon
:
ReadonlyRefOrGetter
<string | null | undefined>,
options
?: UseFaviconOptions,
):
ComputedRef
<string | null | undefined>
export declare function
useFavicon
(
newIcon
?:
MaybeRef
<string | null | undefined>,
options
?: UseFaviconOptions,
):
Ref
<string | null | undefined>
export type
UseFaviconReturn
=
ReturnType
<typeof
useFavicon
>

Source

SourceDemoDocs

Contributors

Anthony Fu
IlyaL
Anthony Fu
Antério Vieira
SerKo
2nofa11
babu-ch
azaleta
Mikhailov Nikita
Jelf
Alex Kozack

Changelog

v12.8.0 on
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.5.0 on
d1fcc - feat: Add link tag if it doesn't exist (#3444)
v10.0.0-beta.5 on
cb644 - refactor!: remove isFunction and isString utils
v10.0.0-beta.4 on
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef

Released under the MIT License.

Build faster with AI
New Masterclass to help you leverage AI in your Vue workflow
Get Early Access