The Vue Instance Flashcards

1
Q

How does every Vue application start and what is the code for it?

A

By creating a new Vue instance with the Vue function

`const vm = new Vue({

//options

})`

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

Vue’s design was partly inspired by…

A

the MVMM pattern

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

What variable is often used for the Vue instance and why?

A

vm because it stands for ViewModel in MVMM

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

What does a Vue application consist of?

A
  • A root Vue instance (created with `new Vue)
  • Optional nested, reusable components
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you configure a Vue instance to behave how you want?

A

By passing it an options object, which controls all behaviors of the instance

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

In essence, what are vue components?

A

Vue components are also vue instances, that accept (almost) all the same options

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

What happens when a Vue instance is created in relation to its data object?

A

Vue adds all the properties in the data object to Vue’s reactivity system

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

What is the one condition for ensuring properties in data are reactive?

A

Properties must exist when the instance is created. Adding a new property after creation will not make it reactive.

This is the reason you must set properties to an empty initial value.

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

What is one way to halt Vue’s reactivity abilities?

A

Before passing an object into the data option, call Object.freeze(obj), and then pass it in.

A frozen object will not react to changes, nor will Vue be able to track changes.

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

Name two properties Vue instances expose.

A

$data - Access to the data object that the Vue instance is observing

$el - The root DOM element that the Vue instance is managing

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

What are 4 initialization steps that the Vue instance goes through?

A
  • Setting up data observation
  • Compiling the template
  • Mounting the instance
  • Updating the DOM when data changes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe what’s going on during the beforeCreate hook.

A
  • Events are initialized and the the lifecycle has began
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe what’s happening during the created hook.

A
  • Injections are available, and reactivity has been initialized
  • No template has been compiled yet
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe what’s happening around the beforeMount hook.

A
  • The template has been rendered but has not been placed in the DOM
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe what’s happening around the mounted hook?

A
  • The template has been compiled and mounted into the DOM
  • Everything is ready
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s happening around the beforeUpdate hook?

A
  • A re-render is about to happen because the reactivity system has received a change in the data it monitors
17
Q

Describe the updated hook.

A
  • A re-render and patch has taken place because some data has been altered, and thus triggered the reactivity system
18
Q

Describe the beforeDestroy hook.

A
  • Happens right after vm.$destroy() is called
  • Nothing has been torn down yet
19
Q

Describe the destroyed hook.

A
  • The watchers, child components, and event listeners have been torn down