Working with data inside Vue methods
Within methods, you can access the properties of the data
object. To do this, you need to access them through this
. Let's look at an example. Let's say we have the following property:
data() {
return {
text: 'str',
}
}
Let's output the value of this property inside the method:
methods: {
show: function() {
alert(this.text);
}
}
Let data
store two numbers:
data() {
return {
num1: 1,
num2: 2,
},
}
Make a method that, when the code is run, will output the sum of our numbers through alert
.