The Vue Instance Flashcards
How does every Vue application start and what is the code for it?
By creating a new Vue instance with the Vue
function
`const vm = new Vue({
//options
})`
Vue’s design was partly inspired by…
the MVMM pattern
What variable is often used for the Vue instance and why?
vm
because it stands for ViewModel in MVMM
What does a Vue application consist of?
- A root Vue instance (created with `new Vue)
- Optional nested, reusable components
How do you configure a Vue instance to behave how you want?
By passing it an options object, which controls all behaviors of the instance
In essence, what are vue components?
Vue components are also vue instances, that accept (almost) all the same options
What happens when a Vue instance is created in relation to its data
object?
Vue adds all the properties in the data
object to Vue’s reactivity system
What is the one condition for ensuring properties in data
are reactive?
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.
What is one way to halt Vue’s reactivity abilities?
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.
Name two properties Vue instances expose.
$data
- Access to the data object that the Vue instance is observing
$el
- The root DOM element that the Vue instance is managing
What are 4 initialization steps that the Vue instance goes through?
- Setting up data observation
- Compiling the template
- Mounting the instance
- Updating the DOM when data changes
Describe what’s going on during the beforeCreate
hook.
- Events are initialized and the the lifecycle has began
Describe what’s happening during the created
hook.
- Injections are available, and reactivity has been initialized
- No template has been compiled yet
Describe what’s happening around the beforeMount
hook.
- The template has been rendered but has not been placed in the DOM
Describe what’s happening around the mounted
hook?
- The template has been compiled and mounted into the DOM
- Everything is ready