I am trying to add up an Object.value, having its adding value bound to the number being inputed in my input through a v-model to total number.
When I input any number then use the @click listener the behaviour is odd, it keeps concatenating whatever I am firing, treating the result as a String instead of a Number.
Interesting that if I comment out the input tag, hence removing the v-model and changing the value on this.shared[2].value to any number greater then 0, the desired behaviour will occur.
<template>
<div>
<input type="number" v-model="shares[2].value">
<p>{{this.shares[0].value}}</p>
<button class="btn btn-primary"
@click="result">Sum An Object Value</button>
</div>
</template>
<script>
export default {
data(){
return {
shares: [
{id: 'BMW', value: 0},
{id: 'Ford', value: 0},
{id:'Apple', value: 0}
]
}
},
methods: {
result(){
this.shares[0].value += this.shares[2].value
}
}
}
</script>
How could I get the appropriate behaviour here?