mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 00:36:14 -04:00
refactor(dry): mutualised duplicated code with withDefaultOnError
This commit is contained in:
parent
208a373fd0
commit
f6cd9b76d3
4 changed files with 10 additions and 35 deletions
|
@ -21,18 +21,13 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import { evaluate } from 'mathjs';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
const expression = ref('');
|
||||
|
||||
const result = computed(() => {
|
||||
try {
|
||||
return evaluate(expression.value) ?? '';
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
const result = computed(() => withDefaultOnError(() => evaluate(expression.value) ?? '', ''));
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue