js directive is a special element attribute that starts with v dash. Their purpose is to apply side effects to the DOM based on the expression provided them. This can be any JavaScript expression and is known as the value of the directive. Some popular directives include vif, vbind, and von.
Before we get into making our own directives, Let's take a look at how some of these built-in directives work. vif is used to conditionally render an element, based on the truthiness of its value. vbind is used for binding reactive data to a specific HTML attribute. The data is provided as the value of the directive, and the attribute that you want to bind the data to is the directive's argument.
Many directives take an argument. which is separated from the directive name by a colon. However, some directives like v else require no argument at all. You might be more familiar writing the v bind directive with its shorthand.
That is just the colon. But that's just a shortcut for convenience. The full directive is v dash bind. Let's also take a look at the v on directive.
The argument for this directive is the event that we want to listen to. And the value is the JavaScript that we want to run whenever the event occurs. This directive supports several modifiers in order to modify how it behaves. One of them is the prevent modifier.
It prevents the browser from performing the default behavior of the event. As you can see, the way we apply these modifiers is with a dot at the end of the directive. And you can actually add as many of these modifiers as you'd like. Awesome.
js directives start with v dash, include an optional argument which is declared with the colon, and can be modified with a dot followed by the modifier name. js directive is a special element attribute that starts with v dash. Their purpose is to apply side effects to the DOM based on the expression provided them. This can be any JavaScript expression and is known as the value of the directive.
Some popular directives include vif, vbind, and von. Before we get into making our own directives, Let's take a look at how some of these built-in directives work. vif is used to conditionally render an element, based on the truthiness of its value. vbind is used for binding reactive data to a specific HTML attribute.
The data is provided as the value of the directive, and the attribute that you want to bind the data to is the directive's argument. Many directives take an argument. which is separated from the directive name by a colon. However, some directives like v else require no argument at all.
You might be more familiar writing the v bind directive with its shorthand. That is just the colon. But that's just a shortcut for convenience. The full directive is v dash bind.
Let's also take a look at the v on directive. The argument for this directive is the event that we want to listen to. And the value is the JavaScript that we want to run whenever the event occurs. This directive supports several modifiers in order to modify how it behaves.
One of them is the prevent modifier. It prevents the browser from performing the default behavior of the event. As you can see, the way we apply these modifiers is with a dot at the end of the directive. And you can actually add as many of these modifiers as you'd like.
Awesome. js directives start with v dash, include an optional argument which is declared with the colon, and can be modified with a dot followed by the modifier name.