I have 5 input fields that I need to get the total of its SUM.
Created data fields and v-model to the fields and at computed: i'm trying to do the SUM
<input type="text" class="form-control" id="ValorImovelPatrimonio" name="ValorImovelPatrimonio" v-model="ValorImovelPatrimonio" required @keydown="$event.keyCode === 13 ? $event.preventDefault() : false" @blur="pegaTotal">
var vue = new Vue({
el: '#app',
data: {
checked : false,
deposito: 1,
patrimonio_nao: false,
ValorImovelPatrimonio: null,
ValorAutosPatrimonio: null,
ValorOutrosPatrimonio: null,
ValorAcoesPatrimonio: null,
ValorInvestimentosPatrimonio: null,
// total: null
},
...
computed: {
total: function(){
return this.ValorImovelPatrimonio + this.ValorAutosPatrimonio;
}
}
What happens:
ValorAutosPatrimonio:"15.000"
ValorImovelPatrimonio:"1.500.000"
total:"1.500.00015.000"
But I expect:
1.515.000
Anyone, please?
ValorAutosPatrimonioandValorImovelPatrimonioare strings. You need to convert them to numbers before doing any arithmetic.