Skip to content

useFavicon

反应式图标

¥Reactive favicon

示例

Change favicon to

用法

¥Usage

js
import { useFavicon } from '@vueuse/core'

const icon = useFavicon()

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

传递源引用

¥Passing a source ref

你可以将 ref 传递给它,源引用的更改将自动反映到你的图标上。

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

js
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

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

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号