Extract value formatting to computed property

This commit is contained in:
Jan Bader 2022-02-07 16:38:26 +00:00
parent 139b6ec636
commit 427e7e5359

View File

@ -2,11 +2,18 @@
import { defineComponent } from "vue"; import { defineComponent } from "vue";
export default defineComponent({ export default defineComponent({
props: ["value"] props: ["value"],
computed: {
formattedValue() {
return this.value.toLocaleString(undefined, {
minimumFractionDigits: 2,
});
}
}
}) })
</script> </script>
<template> <template>
<span :class="value < 0 ? 'negative' : ''">{{value.toLocaleString(undefined, {minimumFractionDigits: 2,})}} </span> <span class="text-right" :class="value < 0 ? 'negative' : ''">{{formattedValue}} </span>
</template> </template>