2022-06-02 00:10:03 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<n-input
|
|
|
|
v-model:value="expression"
|
|
|
|
rows="1"
|
|
|
|
type="textarea"
|
|
|
|
placeholder="Your math expression (ex: 2*sqrt(6) )..."
|
|
|
|
size="large"
|
|
|
|
autocomplete="off"
|
|
|
|
autocorrect="off"
|
|
|
|
autocapitalize="off"
|
|
|
|
spellcheck="false"
|
|
|
|
/>
|
|
|
|
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card v-if="result !== ''" title="Result " mt-5>
|
2022-06-02 00:10:03 +02:00
|
|
|
{{ result }}
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-06-02 00:10:03 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-08-04 22:57:24 +02:00
|
|
|
import { withDefaultOnError } from '@/utils/defaults';
|
2022-06-02 00:10:03 +02:00
|
|
|
import { evaluate } from 'mathjs';
|
|
|
|
import { computed, ref } from 'vue';
|
|
|
|
|
|
|
|
const expression = ref('');
|
|
|
|
|
2022-08-04 22:57:24 +02:00
|
|
|
const result = computed(() => withDefaultOnError(() => evaluate(expression.value) ?? '', ''));
|
2022-06-02 00:10:03 +02:00
|
|
|
</script>
|