Building components Flashcards

1
Q

How do you make the template to reflect the change of a variable defined in setup?

A

By making it reactive (using ref or reactive).

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

What is the difference between ref() and reactive()? (when to use ref() and when to use reactive())

A

ref() can take as arguments primitives (most common: Boolean, String and Number) as well as Objects, while reactive() can only take Objects as arguments. Developers use reactive() mostly for convenience (to avoid using .value all over the code).

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

What can you use to have a value that recomputes every time one or more reactive properties change?

A

A computed function.

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

What can you use when you want to perform some actions when some reactive properties changed?

A

Watch or watchEffect.

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

What is the difference between watch and watchEffect?

A
  1. In watchEffect you don’t have to provide the reactive variables on which it will depend. But in the watch method, you have to specify the list of reactive variables as its first argument.
  2. The watch method runs lazily by default. It does not get executed when the component mounts. But watchEffect runs once when the component mounts then it executes the callback function for the change of dependency variables.
  3. In the watch method, you can access the updated and previous values of the dependent reactive variables inside the callback function. But the watchEffect does not give the updated or previous values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How a components receives data from outside (from the parent component) ?

A

Via props

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

Define a required prop of type Student with the default name: Alexa.

A

props: {
student: {
type: Object as PropType<Student>,
required: true,
default: () => ({ name: Alexa })
}
}</Student>

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

Is the types validation executed when the application is running in production mode?

A

No, all these runtime checks (types, required, validation) are omitted when running the application in production mode.

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

Can you modify a received prop?

A

No, you cannot modify a prop.

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

How can you emit an event from the setup function?

A

defineCOmponent({
….
emits: {
eventName: (argument) => validator();
},
setup(props , { emit }) {
emit(‘customEventName’);
}
})

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

What lifecycle hook is called after component has been mounted (inserted in the DOM)?

A

onMounted

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

What lifecycle hook is called before mounting the component?

A

onBeforeMount

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

What lifecycle hook is called when there is an error in one of the descendent components?

A

onErrorCaptured

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

What lifecycle hook is called when something changed and the component has been rerendered?

A

onUpdated

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

What lifecycle hook is called before rerendering the component?

A

onBeforeUpdate

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