Exploring built-in directives in Vue 3
Vue also provides special HTML attributes called directives. A directive is declared in the opening tag of an HTML element and will affect or provide dynamic behavior or functionality to that element. We can also create our own directives in Vue. Those provided by the framework have a special notation starting with v-
. As for the purpose of this book, let’s explain the most commonly used Vue directives:
v-bind: (shorthand ":")
The v-bind:
directive binds the value of an HTML attribute to the value of a JavaScript variable. If the variable is reactive, each time it updates its value, it will be reflected in the html. If the variable is not reactive, it will be used only once during the initial rendering of the HTML. Most often, we use only the :
shorthand prefix (semi-colon). For example, the my_profile_picture
reactive variable contains a web address to a picture:
<
img :src="my_profile_picture">
The...