Registry / web-framework / vue-debounce

vue-debounce

JSON →
library5.0.1jsnpmunverified

vue-debounce is a Vue.js directive that provides a straightforward way to debounce events, primarily user input, within Vue 3 applications. As of its current stable version, 5.0.1, it exclusively supports Vue 3; users requiring Vue 2 compatibility are directed to the separate `vue2-debounce` package or to remain on v4 of vue-debounce. The library is actively maintained, with a cadence of minor and patch releases, and major versions introducing significant architectural shifts such as the transition to ES modules. Its key differentiators include a simple declarative usage model via the `v-debounce` directive, support for various event listeners, customizable debounce times, and several modifiers like `lock`, `fireonempty`, and `trim` for fine-grained control over debouncing behavior. It supports both global application-level registration and component-level usage.

npm install vue-debounce
INSTALL
IMPORT
SIG · VUE-DEBOUNCE
V
vue-debounce
web-frameworkjavascriptv5.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vueDebounce
import vueDebounce from 'vue-debounce'
const vueDebounce = require('vue-debounce')
Since v5.0.0, vue-debounce is an ES module. CommonJS `require` syntax will fail or lead to incorrect imports. Use the default import for global registration.
DebounceOptions
import type { DebounceOptions } from 'vue-debounce'
Import for TypeScript type definitions to configure global debounce options.
Vue 2 support
import vueDebounce from 'vue2-debounce'
import vueDebounce from 'vue-debounce'
For Vue 2 applications, use the dedicated `vue2-debounce` package. `vue-debounce` v5+ is Vue 3 only.

This quickstart demonstrates how to globally register the `v-debounce` directive in a Vue 3 application, including custom default options. It also shows basic template usage with a specified debounce time and modifiers.

import vueDebounce from 'vue-debounce'; import { createApp } from 'vue'; import App from './App.vue'; const app = createApp(App); // Register the directive globally with custom options app .directive('debounce', vueDebounce({ lock: false, // Lock all debounced inputs by default defaultTime: '500ms', // Default debounce time for directives without a specified time listenTo: ['keyup', 'change'] // Listen to multiple events })) .mount('#app'); // In your App.vue template: // <template> // <div> // <input v-debounce:800ms.trim="mySearchFunction" placeholder="Search..." /> // <button v-debounce="myClickHandler">Click Me</button> // </div> // </template> // In your component script: // export default { // methods: { // mySearchFunction(value) { // console.log('Debounced search for:', value); // }, // myClickHandler() { // console.log('Debounced click!'); // } // } // }
Debug
Known issues
breakingVue Debounce v5.0.0 completely removes support for Vue 2. If your project relies on Vue 2, you must either stay on `vue-debounce` v4 or migrate to the dedicated `vue2-debounce` package.
fix
For Vue 2 projects, install `vue2-debounce` (npm i vue2-debounce) or downgrade `vue-debounce` to v4 (npm i vue-debounce@4).
affects: >=5.0.0
breakingAs of v5.0.0, `vue-debounce` is published as an ES module (`type: 'module'` in package.json). This changes how it should be imported, particularly in CommonJS environments or older build setups.
fix
Ensure you are using ESM `import` statements (e.g., `import vueDebounce from 'vue-debounce'`) and that your build tools are configured to handle ES modules correctly. Avoid `require('vue-debounce')`.
affects: >=5.0.0
breakingVue Debounce v4.0.0 removed the `getDirective` flow, simplifying usage by separating Vue 2 and Vue 3 imports and direct directive registration. Attempts to use `getDirective` will fail.
fix
For Vue 3, directly import and register `vueDebounce`. For Vue 2, use the `vue2-debounce` package which provides the Vue 2 compatible directive directly.
affects: >=4.0.0
gotchaThe `trim` option/modifier, introduced in v3.0.0, only affects the internal logic for determining if an input should fire (e.g., preventing empty string callbacks). The value passed to your debounced function will *not* be automatically trimmed.
fix
If you need the trimmed value in your callback, manually apply `String.prototype.trim()` within your debounced function: `myFunction(value) { const trimmedValue = value.trim(); /* ... */ }`.
affects: >=3.0.0
gotchaThe behavior of `fireonempty` was made stricter in v3.0.0 to fix a bug. If you relied on previous looser behavior, your debounced function might not fire when an input is emptied.
fix
Review the `fireonempty` modifier/option usage and test its behavior. Adjust your logic or explicitly set `fireOnEmpty: true` if needed, understanding the stricter conditions for firing on empty input.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: (0 , vue_debounce__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
Attempting to import `vue-debounce` (v5+) in a CommonJS context or with a bundler configuration that does not correctly resolve ES modules.
fix
Ensure your project uses ES module `import` syntax (`import vueDebounce from 'vue-debounce'`) and that your build environment (e.g., Webpack, Vite, Rollup) is configured to handle ES modules properly.
[Vue warn]: Failed to resolve directive: debounce
The `v-debounce` directive has not been correctly registered with your Vue application, either globally or locally within the component.
fix
Globally: `app.directive('debounce', vueDebounce(...))` in your `main.js`/`main.ts`. Locally: `directives: { debounce: vueDebounce(...) }` in your component options, or within `<script setup>` in Vue 3 via `const vDebounce = vueDebounce(...)`.
Cannot read properties of undefined (reading 'install')
Attempting to use `vue-debounce` v5+ (which is Vue 3 only) with a Vue 2 application.
fix
Migrate to `vue2-debounce` for Vue 2 projects, or downgrade `vue-debounce` to v4.
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies
vuerequiredRuntime peer dependency for Vue.js applications.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources