Energyflow: fix NaN values (#21084)
This commit is contained in:
parent
7294c8b959
commit
f6bcc49e80
1 changed files with 17 additions and 2 deletions
|
|
@ -5,6 +5,7 @@
|
|||
<script lang="ts">
|
||||
import { CountUp } from "countup.js";
|
||||
import { defineComponent, type PropType } from "vue";
|
||||
import type { Timeout } from "@/types/evcc";
|
||||
const DURATION = 0.5;
|
||||
|
||||
export default defineComponent({
|
||||
|
|
@ -17,11 +18,12 @@ export default defineComponent({
|
|||
data() {
|
||||
return {
|
||||
instance: null as CountUp | null,
|
||||
timeout: null as Timeout | null,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
to(value) {
|
||||
this.instance?.update(value);
|
||||
this.update(value);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
|
|
@ -40,11 +42,24 @@ export default defineComponent({
|
|||
},
|
||||
unmounted() {
|
||||
this.instance = null;
|
||||
if (this.timeout !== null) {
|
||||
clearTimeout(this.timeout);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
forceUpdate() {
|
||||
this.instance?.reset();
|
||||
this.instance?.update(this.to);
|
||||
this.update(this.to);
|
||||
},
|
||||
update(value: number) {
|
||||
// debounced to avoid rendering issues
|
||||
// @see https://github.com/inorganik/countUp.js/issues/330#issuecomment-2697595198
|
||||
if (this.timeout !== null) {
|
||||
clearTimeout(this.timeout);
|
||||
}
|
||||
this.timeout = setTimeout(() => {
|
||||
this.instance?.update(value);
|
||||
}, 100);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue