Executing code in Vue views
You can execute various JavaScript code in curly brackets. Let's look at this with an example. Let's say we have two properties with numbers - var1 and var2:
data() {
return {
var1: 1,
var2: 2,
}
}
Let's, for example, add up the values of our properties:
<template>
{{ var1 + var2 }}
</template>
The result of this code will be the following HTML:
<div id="app">
3
</div>
Let data store the following:
data() {
return {
num: 5,
}
}
Print the square of the property num.
Let data store the following:
data() {
return {
num1: 1,
num2: 2,
num3: 3,
}
}
Print the sum of the properties num1, num2 and num3.