⬅️ Back to Table of Contents
📄 index.ts
📊 Analysis Summary
Metric |
Count |
🔧 Functions |
2 |
📦 Imports |
9 |
🟢 Vue Composition API |
1 |
📐 Interfaces |
1 |
📑 Type Aliases |
1 |
📚 Table of Contents
🛠️ File Location:
📂 packages/core/useFavicon/index.ts
📦 Imports
Name |
Source |
ReadonlyRefOrGetter |
@vueuse/shared |
ComputedRef |
vue |
MaybeRef |
vue |
MaybeRefOrGetter |
vue |
Ref |
vue |
ConfigurableDocument |
../_configurable |
toRef |
@vueuse/shared |
watch |
vue |
defaultDocument |
../_configurable |
Vue Composition API
Name |
Type |
Reactive Variables |
Composables |
watch |
watch |
none |
none |
Functions
useFavicon(newIcon: ReadonlyRefOrGetter<string | null | undefined>, options: UseFaviconOptions): ComputedRef<string | null | undefined>
Code
export function useFavicon(
newIcon: ReadonlyRefOrGetter<string | null | undefined>,
options?: UseFaviconOptions
): ComputedRef<string | null | undefined>
-
JSDoc:
/**
* Reactive favicon.
*
* @see https://vueuse.org/useFavicon
* @param newIcon
* @param options
*/
-
Parameters:
newIcon: ReadonlyRefOrGetter<string | null | undefined>
options: UseFaviconOptions
- Return Type:
ComputedRef<string | null | undefined>
applyIcon(icon: string): void
Code
(icon: string) => {
const elements = document?.head
.querySelectorAll<HTMLLinkElement>(`link[rel*="${rel}"]`)
if (!elements || elements.length === 0) {
const link = document?.createElement('link')
if (link) {
link.rel = rel
link.href = `${baseUrl}${icon}`
link.type = `image/${icon.split('.').pop()}`
document?.head.append(link)
}
return
}
elements?.forEach(el => el.href = `${baseUrl}${icon}`)
}
- Parameters:
icon: string
- Return Type:
void
- Calls:
document?.head
.querySelectorAll
document?.createElement
icon.split('.').pop
document?.head.append
elements?.forEach
Interfaces
UseFaviconOptions
Interface Code
export interface UseFaviconOptions extends ConfigurableDocument {
baseUrl?: string
rel?: string
}
Properties
Name |
Type |
Optional |
Description |
baseUrl |
string |
✓ |
|
rel |
string |
✓ |
|
Type Aliases
UseFaviconReturn
type UseFaviconReturn = ReturnType<typeof useFavicon>;