What Are Directives? Why Are They Useful?

Custom directives are a way of making our code reusable similar to mixins but instead of reusing component functionalities, directives let us create single methods that are reusable these custom directives are great for DOM access/manipulation. Vue comes with a few default directives that you are guaranteed to have seen/used before like v-modelv-bind & v-show. It’s a lot easier to understand once we see some examples of what we can do with custom directives.

Vue also allows you to register your own custom directives, where would custom directives would still be useful? An example would be focusing on an input element when the page is loaded.

#nuxtjs #vuejs #javascript #server-side-rendering

Nuxt — Creating Custom Directives For Static & SRR Sites
12.70 GEEK