WIP Исправил ошибку срабатывания интервала

This commit is contained in:
DwCay
2023-05-23 14:42:17 +03:00
parent 7a39fc8961
commit 971ef269fe
2 changed files with 17 additions and 3 deletions

View File

@@ -51,6 +51,7 @@
import BaseInput from "@/components/base/BaseInput";
import BaseInputContainer from "@/components/base/BaseInputContainer.vue";
import { ruleNumberInput } from "@/shared/utils/rulesInputs";
import { roundedNumber } from "@/shared/utils/methodsObjects";
export default {
name: "BaseInputNumber",
@@ -58,7 +59,9 @@ export default {
data() {
return {
intervalId: 0,
timeoutId: 0,
ruleNumberInput: [(val) => ruleNumberInput(val, this.max, this.min)],
roundedNumber: roundedNumber,
};
},
props: {
@@ -163,18 +166,23 @@ export default {
}
},
fastIncrement() {
this.timeoutId = setTimeout(() => {
this.intervalId = setInterval(() => this.increment(), 100);
}, 500);
},
fastDecrement() {
this.timeoutId = setTimeout(() => {
this.intervalId = setInterval(() => this.decrement(), 100);
}, 500);
},
deleteInterval() {
clearTimeout(this.timeoutId);
clearInterval(this.intervalId);
},
},
watch: {
value(val) {
this.value = Number(val).toFixed(this.rounding);
this.value = this.roundedNumber(val, this.rounding);
},
},
computed: {

View File

@@ -0,0 +1,6 @@
export function roundedNumber(val, digits, rounded = "floor") {
let fraction = 10 * digits;
return fraction
? Math[rounded](val * fraction) / fraction
: Math[rounded](val);
}