useScriptTag
Creates a script tag, with support for automatically unloading (deleting) the script tag on unmount.
Package: @vueuse/core
Category: Browser
Usage
import { useScriptTag } from '@vueuse/core'
useScriptTag(
'https://player.twitch.tv/js/embed/v1.js',
// on script tag loaded.
(el: HTMLScriptElement) => {
// do something
},
)Options
| Option | Type | Default | Description |
|---|---|---|---|
| immediate | boolean |
true | Load the script immediately |
| async | boolean |
true | Add async attribute to the script tag |
| type | string |
text/javascript | Script type |
| manual | boolean |
false | Manual controls the timing of loading and unloading |
| attrs | Record<string, string> |
- | Add custom attribute to the script tag |
| nonce | string |
undefined | Nonce value for CSP (Content Security Policy) |
Returns
| Name | Type |
|---|---|
| scriptTag | shallowRef<HTMLScriptElement | null> |
| load | Ref |
| unload | Ref |