Templates Flashcards

1
Q

If greetings is a property of the component, you can display its value in your template using?

A

Interpolation: {{ greetings }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If author is a property of a component App and contains { name: ‘Tatiana’ }, how can you display ‘Tatiana’?

A

{{ author.name }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you add 1 to a reactive property defined as const count = ref(0)?

A

count.value = count.value + 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you listen to a click event on a button?

A

<button @click=”doSomething” />

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If author is a property of a component and contains { name: ‘Tatiana’ }, what does {{ user }} display?

A

{ “name”: “Tatiana” }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You can add/remove a class orange to a div when isOrange is true/false, using…?

A

<div :class=”{ orange: isOrange}”>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you stop the default behavior of an event? (for example don’t reload the page when submitting a form)

A

By using the .prevent modifier: @submit.prevent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you stop an event from propagation?

A

By using the .stop modifier: @click.stop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the .passive modifier do?

A

It tells the browser that the default behavior shouldn’t be prevented, and that it should be done without waiting for the listener function to return.

It can be very handy if you want to do something on an event that happens very often, like scroll or mousemove, but don’t want to slow down the scrolling of your application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What modifier to use if you want an event listener to execute only when the event is from the element where you
declared it, and not bubbling from one of its children?

A

.self

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the .capture modifier?

A

It allows to capture an
event bubbling from a child, and to handle it first in its handler before letting the child handling it
itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What directive to use if you want to display part of the template only if a certain condition is true?

A

v-show or v-if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between v-if and v-show?

A

v-if removes the content from the DOM, and re-creates it if necessary.
v-show only hides/show the content using css display rule.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to hide a component while Vue is compiling it? (what directive)

A

with v-cloak

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to loop through a list of element in the template?

A

using v-for directive

<div> </div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why do we use :key in v-for?

A

To help Vue keep track of which item from the array corresponds to
which DOM element.

17
Q

What does the v-once directive do?

A

When applied to an element, the element and all its children will only render once, and then Vue will stop caring about updating this part.

18
Q

How to insert dynamic html into the template?

A

using v-html directive