Intro to Vue.js (Week 7, part #1) Flashcards

1
Q

What is Vue.js?

A

1) A progressive JS framework for building user interfaces
2) Designed to be incrementally adoptable
3) Capable of powering sophisticated SPAs
4) A (powerful) layer of abstraction for JavaScript

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

What is templating?

A

A way of separating HTML structure from the content {{…}}

E.g.

[div]

Counter: {{ counter }}

[/div]

Templating allows to bind values from the model into the view.

In Vue, this can be achieved using simple HTML bindings.

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

Explain the following:

const Counter = {

 data() {

      return {

           counter: 0

     }

 }

}

Vue.createApp(Counter).mount(‘#counter’)

A

Create a new Vue object. The Vue object:

1) Is mounted to an element with value ‘#counter’. This property ‘binds’ this Vue instance to the element with id of ‘counter’.
2) A property called data() that returns a POJO with a programmer-defined name-value pair: name of counter, and a value of 0

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

Vue models are POJOs. What is this?

A

Plain Old Javascript Objects

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

What is the difference between Directives and Filters?

A

Directives:

custom HTML attributes that tell vue.js to do something to the DOM element (v-if:)

Filters :

can be used to apply common text formatting. In mustache interpolation of v-bind.

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

What happens when a vue instance is created?

A

It adds all of its properties in the data object to Vue’s reactivity system.

When the values of those properties change, the view will “react”, updating to match the new values.

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

What is the viewModel in terms of Vue.js?

A

An object that syncs the model and the view

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

What are Vue directives considered to be? Give some examples.

A

custom attributes

v-if:

v-on:click

v-for:

v-bind:

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

What does Vue allow you to link together?

A

data and the Document Object Model, a.k.a.

DOM (via the virtual DOM)

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

What happens once the data and DOM are linked?

A

things are then reactive

1) User changes the DOM (e.g. enters information), the data is updated;
2) JavaScript changes the data, the DOM is updated

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

What do Vue directives provide?

A

Special reactive behaviour based on some logic

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

What are the values in data() called?

A

Properties

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

What is the general structure for Vue components?

A

const SomeComponent = {

data() {

return: {

someProperty: ‘hello!’

}

},

methods: {

}

}

Vue.createApp(SomeComponent).mount(‘#some-component’)

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

Give an example of a Vue directive in code.

A

Reverse Message

Then in the methods section, there is a method called reverseMessage()

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

In Vue components, what key word is used to access the variables that make up your model?

A

this

e.g. this.message = this.newMessage

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

Explain the ‘computed’ feature of Vue

A

1) A derived property
2) Has getters and (sometimes) setters
3) You don’t call a computed, you reference it
4) You don’t pass parameters to a computed
5) e.g. convert cents to dollars

17
Q

Explain the ‘method’ feature of Vue

A

1) A traditional function/method of JavaScript
2) You must call it
3) You can pass parameter

18
Q

What are some (5) other features of Vue?

A

1) computed
2) method
3) Vue lifecycle
4) watchers
5) components

19
Q

What is interpolation?

A

Interpolation refers to the act of taking one or more variables, evaluating their values, and displaying the result in the template.

It can be as simple as a ‘Hello World’ string, but it can also be the result of a more complex expression.

20
Q

What are Vue Directives?

A

Vue provides a set of built-in directives prefixed with v- that allow DOM manipulation inside the template in response to model changes.

For example, the v-if directive would show/hide an element based on the model value.

21
Q

What are Vue Filters?

A

Filters can be used with model values to modify the given value for displaying in the view.

For example, you may want to display some text in all caps.

Here, rather than modifying or duplicating the initial model value, we can apply a filter that will dynamically transform the value for the display.