Search code examples
javascriptvue.jslodash

How to have a dynamic time in debounce/throttle?


I'm trying to use something like this in Vue:

props(){
   debouncing: {type: Number, default: 0}
},
methods: {
    clicked: _.debounce(function() {
        this.$emit('click');
    }, this.debouncing),
}

However, this won't work when for example this is set: debouncing = 4000


Solution

  • thanks to @RoyJ's comment:

    computed:{
        clicked(){
            return _.debounce(this.click, this.debouncing)
        }
    },
    methods:{
        click(){
           this.$emit('click');
        },
    }