-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Version: Vue 3, debounce v3.0.1
Browser: Chrome
I'm attempting to use this package to debounce a method that runs when the @input event of a textarea is fired. Because of my setup, I'm just using debounce directly. I have the debounce module imported, and I wrap the function to debounce inside of a watcher. The result is that when the @input event is fired multiple times in rapid succession, my method call is delayed for the amount of time specified, but then runs for each event that was triggered. I expected it to only run once since the event was fired multiple times within the wait period.
My code is like this:
<Textarea id="content" @input="contentChanged" v-model="form.content" />
import { debounce } from 'vue-debounce';
export default {
setup (props) {
const form = useForm({
content: null
});
return form;
},
data() {
changes: 0
},
methods: {
contentChanged(e) {
this.changes++;
},
performAction(val) {
console.log(val);
}
},
watch: {
changes: function(val) {
let newContent = this.form.content;
debounce(val => {
this.performAction(val);
}, 3000)(newContent);
}
}
}
When I type the word "test" into the textarea, 3 seconds go by, then the following is printed to the console:
t
te
tes
test
How do I make debounce... debounce? Thanks for the help.