I am building simple calculator with Vue, and I don't know how to transform string into math operation. I already have string building code.
<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>
Thank you in advance :).