In Vue 2, components are the go-to strategy to use, be it keeping things DRY or abstracting away some functionality. However, another approach that you can take is to utilize custom directives.
Making our own directives
Understanding custom directives
As we discussed earlier in this book, directives help us explain to Vue what kind of behavior we would like to attach to a piece of markup. As we have previously seen, there are a number of directives that come built-in with Vue. Some examples are v-on, v-if, v-model, and so on. As a quick refresher, a directive is an HTML attribute that starts with v-.
When we need to build a custom directive, we simply provide a custom word after the hyphen. For example, we could create a custom...