Guide: Component Basics Flashcards
At it’s core, what is a component, and what does this mean?
A reusable Vue instances with a name that can be used as a custom element inside a root Vue instance, created with new Vue
.
Means they accept the same options as new Vue
since they are simply Vue instances. They don’t accept root-specific options like el
though.
Why must a component’s data option be a function?
So that each instance can maintain an independent copy of the returned data object.
What two ways can components be registered?
Globally or locally.
What are props? What must we do to make sure they’re accepted?
- They are custom attributes that you can register on a component
- We must include it in the list of props that the component will accept
Let’s say we emit a custom value with an event from a child to parent. How do we do this and how do we access it?
- We emit it using the
$emit
’s 2nd parameter - Handling inline
- use
$event
:v-on:enlarge-text="bodyFontSize = $event"
- use
- Handling with a string of a method name
- the first parameter passed to the method will be the event
What is input v-model="searchText" /\>
equal to?
input :value="searchText" @input="searchText = $event.target.value"\>
What is custom-input v-model="searchText"\>
What must happen in the component for this to work?
custom-input :value="searchText" @input="searchText = $event"\>
- Bind the
value
attribute to avalue
prop - On
input
, emit its own custominput
event with the new value
How do we pass content to a componet, like a normal HTML element?
For example: alert-box\>Something happened /alert-box\>
Define a slot\>/slot\>
element in the component.
How can we utilize dynamic components?
- Use the
is
attribute of thecomponent>
element - We can either pass in:
- the name of a registered component
- a component’s options object