Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useObjectUrl.md
1---2category: Browser3---45# useObjectUrl67Reactive URL representing an object.89Creates an URL for the provided `File`, `Blob`, or `MediaSource` via [URL.createObjectURL()](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL) and automatically releases the URL via [URL.revokeObjectURL()](https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL) when the source changes or the component is unmounted.1011## Usage1213```vue14<script setup lang="ts">15import { useObjectUrl } from '@vueuse/core'16import { shallowRef } from 'vue'1718const file = shallowRef()19const url = useObjectUrl(file)2021function onFileChange(event) {22file.value = event.target.files[0]23}24</script>2526<template>27<input type="file" @change="onFileChange">2829<a :href="url">Open file</a>30</template>31```3233## Component Usage3435```vue36<template>37<UseObjectUrl v-slot="url" :object="file">38<a :href="url">Open file</a>39</UseObjectUrl>40</template>41```4243## Type Declarations4445```ts46/**47* Reactive URL representing an object.48*49* @see https://vueuse.org/useObjectUrl50* @param object51*/52export declare function useObjectUrl(53object: MaybeRefOrGetter<Blob | MediaSource | null | undefined>,54): Readonly<Ref<string | undefined, string | undefined>>55```56