[Vuejs]-Vue.js interpolation values sum

0πŸ‘

βœ…

I see no reason to manipulate data with operations on the template in this case.
The best (and simple) way, probably is to sum that values in your js code and render the result at template as another data property.

Although there is a Vue magic trick that allows you to made that.
It is called Computed Properties. Where you will be β€˜listening’ some dependent data to create another data.

I totally recomend that you read Computed Properties documentation and see how it works

Here is the link:

https://v2.vuejs.org/v2/guide/computed.html

πŸ™‚

3πŸ‘

<span>{{value1 + value2}}</span>

0πŸ‘

Inside the {{}} you can run any JS really, so you should make a method that handles adding the 2 variables and inside that method it can check that both are numbers and handle converting strings if needed. Or you could try to turn this logic into a computed property.

Leave a comment