1.

What is the directive in Vue.js?

Answer»

Directive is a PIECE of instruction to perform a certain task. In vue.js a directive is a sign that that directs the LIBRARY to perform an action to the DOM. Directives in Vue.js are much simpler to understand compared to in Angular.js. Directives in vue.js are in HTML prefix format. Some of the directives INCLUDE; V-show, v-if, v-on, v-for, v-bind and v-model.

They appear in the following format;

<element Prefix-directiveId=”[argument:] expression [| filters…]”> </element>

Directives give permission to the template to act according to the changes in accordance to the defined logic by use of methods, data PROPERTIES and inline expressions. An example of a directive is below.

<SignUpButton V-On:click= “doSignup” />

Here, a v-on directive is used to implement a click on the component. The message is to perform or allow the user to sign up. Apart from the above-mentioned directives, vue.js allows us to define our own directives based on what we need to perform. V directives are easier to understand and implement in the development world. Developers are prioritizing it although prior knowledge in Angular or any other structure is an added advantage. Prior knowledge provides a baseline for understanding how Document Object Model works and how directives manipulate it.



Discussion

No Comment Found

Related InterviewSolutions