useFavicon
リアクティブなファビコン
デモ
ファビコンを変更するには
使用方法
js
import { useFavicon } from '@vueuse/core'
const icon = useFavicon()
icon.value = 'dark.png' // change current icon
ソースrefの受け渡し
ref
を渡すことができます。ソースrefからの変更は、自動的にファビコンに反映されます。
js
import { useFavicon, usePreferredDark } from '@vueuse/core'
import { computed } from 'vue'
const isDark = usePreferredDark()
const favicon = computed(() => isDark.value ? 'dark.png' : 'light.png')
useFavicon(favicon)
ソースrefが渡されると、返されるrefはソースrefと同一になります。
ts
const source = ref('icon.png')
const icon = useFavicon(source)
console.log(icon === source) // true
型定義
typescript
export interface UseFaviconOptions extends ConfigurableDocument {
baseUrl?: string
rel?: string
}
/**
* Reactive favicon.
*
* @see https://vueuse.dokyumento.jp/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>
ソースコード
コントリビューター
変更ログ
v12.0.0-beta.1
2024/11/21v10.5.0
2023/10/7v10.0.0-beta.5
2023/4/13cb644
- refactor!: isFunction
および isString
ユーティリティの削除v10.0.0-beta.4
2023/4/134d757
- feat(types)!: MaybeComputedRef
の名前を MaybeRefOrGetter
に変更10e98
- feat(toRef)!: resolveRef
の名前を toRef
に変更