Module 3 - Rendering conditional content and lists Flashcards
what is v-if?
v-if is a Vue directive that based on a truthy/falsy value adds or removes a DOM element from the DOM
what is v-show?
v-show is a Vue directive that either shows or hides using css a DOM element based on a truthy/falsy value
What is the difference between v-if and v-show?
v-show hides or shows a DOM element with css while v–if removes the element completely from the DOM
what is v-else
v-else allows for the next adjacent element to be displayed if the current element is not going to be displayed because v-if or v-else-if.
what is v-else-if
v-else-if allows for the next adjacent element to be displayed if it meets a certain condition if the current element is not going to be displayed because v-if.
what is v-for
v-for allow us to display a list of elements or a list of fields in an object. the syntax is v-for=”thing in things” {{thing}}
How do you get the index of the item currently being worked on in v-for
in order to get the index you need to use the following syntax <li>v-for=”(goal, index) in goals” {{goal}} - {{index}} </li>
How do you get the key in a v-for loop going over an object
You use the following syntax:
<li>v-for="(value,key) in {'name':'arik', age:47}" {{key}} - {{value}}</li>
You can also get the index using the following syntax
<li>v-for="(value,key,index) in {'name':'arik', age:47}" {{key}} - {{value}} - {{index}}</li>
What would the following syntax produce
li v-for=”val in 10”){{val}}(/li
This syntax will create a list with 1-10 as the values in each li
what does @click.stop do?
@click.stop is a directive that binds the click event to a function but also prevents the event from propagating to other elements along the chain. If we don’t specify a method to be executed we just stop the propagation of the event without activating any method.
What is the key attribute?
The key attribute is used to uniquely identify a DOM element in v-for. It should be used everywhere we use v-for to avoid reuse element bugs in Vue