I'm in the process of creating a basic calculator using Vue, but I'm stuck on how to convert a string into a mathematical operation. I've already written the code for building the strings.
<template>
<div>
<input type="number" placeholder="number" v-model="number">
<button @click = "addToOperation('+')">+</button>
<button @click = "addToOperation('-')">-</button>
<button @click = "addToOperation('*')">*</button>
<button @click = "addToOperation('/')">/</button>
</div>
</template>
<script>
export default {
data() {
return {
number: '',
operation: ''
}
},
methods: {
addToOperation(sign) {
this.operation += this.number + sign
}
}
}
</script>
Appreciate your help on this :).