vue-plugin-load-script is a Vue plugin designed for dynamically injecting and removing remote JavaScript files into a web application. It is fully compatible with Vue 3, with the current stable version being 2.1.1. For Vue 2 compatibility, users need to install version 1.x.x. The plugin offers both Composition API (`loadScript`, `unloadScript`) and Options API (`this.$loadScript`, `this.$unloadScript`) interfaces, providing flexibility for different project architectures. Its primary utility lies in integrating third-party SDKs or external libraries like Google Maps, Stripe.js, or analytics scripts that require dynamic loading after the initial application render. The project maintains an active status with updates typically tied to Vue major version releases or critical bug fixes, rather than a fixed release schedule. A key differentiator is its straightforward API for managing the lifecycle of external scripts within a Vue application.
npm install vue-plugin-load-scriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to globally register the plugin for Options API usage and then dynamically load an external script (e.g., Google Maps API) using the Composition API's `loadScript` function within a component's `onMounted` hook.
For Vue 2 projects, install `vue-plugin-load-script@^1.x.x`. For Vue 3 projects, ensure you are on `vue-plugin-load-script@^2.x.x` and have Vue 3 installed.
Always store the script URL in a constant or variable and reuse it for both `loadScript` and `unloadScript` calls to ensure consistency.
Always include `.catch()` or `try/catch` blocks when calling `loadScript` to handle potential errors gracefully and provide user feedback. Verify script URLs and ensure they are publicly accessible.
For Composition API, import and use the named exports `loadScript` and `unloadScript` directly: `import { loadScript, unloadScript } from 'vue-plugin-load-script';`. For Options API, ensure the plugin is registered with `app.use(LoadScript)`.For Vue 2 projects, install `vue-plugin-load-script@^1.x.x`. For Vue 3, ensure you are creating your app with `createApp` from 'vue'.
Add `import { loadScript } from 'vue-plugin-load-script';` to your script where `loadScript` is used.Within `setup()`, use the named import `loadScript`: `import { loadScript } from 'vue-plugin-load-script';` then call `loadScript(...)`. If in an Options API component, ensure the plugin is registered with `app.use(LoadScript)`.Verify the URL used for `unloadScript` is identical, including query parameters, to the URL used for `loadScript`. Store the URL in a constant to prevent inconsistencies.
No dependency data recorded yet.