Guide: Component Basics Flashcards

1
Q

At it’s core, what is a component, and what does this mean?

A

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.

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

Why must a component’s data option be a function?

A

So that each instance can maintain an independent copy of the returned data object.

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

What two ways can components be registered?

A

Globally or locally.

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

What are props? What must we do to make sure they’re accepted?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?

A
  • We emit it using the $emit’s 2nd parameter
  • Handling inline
    • use $event: v-on:enlarge-text="bodyFontSize = $event"
  • Handling with a string of a method name
    • the first parameter passed to the method will be the event
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is input v-model="searchText" /\> equal to?

A

input :value="searchText" @input="searchText = $event.target.value"\>

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

What is custom-input v-model="searchText"\>

What must happen in the component for this to work?

A

custom-input :value="searchText" @input="searchText = $event"\>

  • Bind the value attribute to a value prop
  • On input, emit its own custom input event with the new value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we pass content to a componet, like a normal HTML element?

For example: alert-box\>Something happened /alert-box\>

A

Define a slot\>/slot\> element in the component.

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

How can we utilize dynamic components?

A
  • Use the is attribute of the component> element
  • We can either pass in:
    • the name of a registered component
    • a component’s options object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly