<template>
<label>
<input
type="checkbox"
@change="debouncedCheckboxChange"
v-model="form.c1"
/>
Check 1
</label>
<label>
<input
type="checkbox"
@change="debouncedCheckboxChange"
v-model="form.c2"
/>
Check 2
</label>
<pre>{{ form }}</pre>
</template>
<script>
const debounce = (handle, duration = 0) => {
let timeout = null;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => handle.apply(this, args), duration);
};
};
export default {
name: 'App',
data() {
return {
form: {}
};
},
methods: {
checkboxChange() {
this.form.date = Date.now();
}
},
created() {
this.debouncedCheckboxChange = debounce(this.checkboxChange, 1500);
}
};
</script>
Пример.
Документация.