Helper Methods in Vue
You can make helper methods that will be used inside other methods. Such methods should also be accessed via this. Let's look at an example. Let's say we have the following method:
show: function() {
alert(this.text);
}
Let's create an auxiliary method that will capitalize the first letter of the passed string:
cape: function(str) {
return str[0].toUpperCase() + str.slice(1);
}
Let's use a helper method inside the main method:
methods: {
show: function() {
let text = this.cape(this.text);
alert(text);
},
cape: function(str) {
return str[0].toUpperCase() + str.slice(1);
}
}
Create a helper method that will receive a number as a parameter and return the day of the week corresponding to this number.
Create a main method that will display the name of the current day of the week.