After adding a debounce function in VueJs, I noticed that it works perfectly when passing the number of milliseconds directly. However, if I use a reference to a prop, it seems to be ignored.
Here's a summary of the props:
props : {
debounce : {
type : Number,
default : 500
}
}
Below is the watch option causing issues:
watch : {
term : _.debounce(function () {
console.log('Debounced term: ' + this.term);
}, this.debounce)
}
And here is an alternative watch option that works without any problems:
watch : {
term : _.debounce(function () {
console.log('Debounced term: ' + this.term);
}, 500)
}
I have a feeling that it could be related to a scope problem, but I'm uncertain about how to resolve it. When I modify the watch method as shown below:
watch : {
term : function () {
console.log(this.debounce);
}
}
I can see the correct debounce value (500) displaying in the console.