Skip to content
On this page

useFavicon

响应式 favicon

Reactive favicon

例子

Change favicon to

Usage

js
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

传递一个ref(Passing a source ref)

您也可以传递 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)
import { computed } from 'vue'
import { useFavicon, usePreferredDark } from '@vueuse/core'

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

useFavicon(favicon)

传递ref时,返回引用将与ref相同

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
const source = ref('icon.png')
const icon = useFavicon(source)

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

Type Declarations

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: MaybeReadonlyRef<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>
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: MaybeReadonlyRef<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

Category
Export Size
930 B
Last Changed
7 months ago

SourceDemoDocs

贡献者(Contributors)

日志(Changelog)

No recent changes

Released under the MIT License.