Abstracting functionality using methods
Most of the components shown within tutorials and training, such as the ones shared in this book so far, always appear to be easy to read and extremely small, but this is not always the case. Components written in real applications can easily get bloated with logic and become very hard to read. Most of the time, this complexity is the result of multiple iterations and feature changes.
It is very important to try and keep the components as clean as possible. The easiest way to achieve this is by abstracting the logic from the HTML and moving it within <script>
, but what can we use to simplify our components?
This is where methods come in handy. Methods are JavaScript functions that can be used within a Vue.js component instance. Methods can be described as helpers that allow you to perform an action within your component.
Methods could be used in a wide variety of cases, from fetching data from an API to validating user input, and...