Answer the question
In order to leave comments, you need to log in
When a checkbox is clicked, wait for another one to be clicked or submit a request. How can this be organized?
I need to wait 1.5 seconds for another checkbox to be pressed when selecting one checkbox or send a request. How can this expectation be organized?
Answer the question
In order to leave comments, you need to log in
<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>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question