vuejs Flashcards

1
Q

vue: a directive is an

A

expression you write in the template starting with v-

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

vue: To interpolate a variable just once (so it wont be reactive)

A

add v-once tag attribute and put {{varName}} into middle of tag

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

vue: The directive for showing or hiding an element based on the boolean value of a variable

A

v-if=”boolVar”

Note:
v-else for opposite

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

vue: To render text or html using a directive

A

v-text or v-html

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

vue: To make a for loop directive

A

v-for=”item in myArray” and to get attribue {{item.name}}

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

vue: To make a class conditional on a context variable

A

v-bind:class=”{class-name: boolVar}”

note: the varName should return true or false

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

vue: To make the value of css in the style attribute be the value of a variable

A

v-bind:style=”{color: varName}”

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

vue: To register a component, type

A

Vue.component(“component-name”, {template: “string”})

of
Vue.component(“component-name”, {template: “#id-name”})

and the template would look like -template id=”id-name”>…-/template>

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

vue: To render a component in the template

A

-component-name> -/component-name>

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

vue: To make a vue widget on your page, type

A
new Vue({
  el: '#element',
  data: {key: 'value'}
  methods: {funcName: function() {},  funcName: function() {}}
})

note: You can have multiple widgets in one page and each would need their own intependant vue instance.

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

vue: To get data from the data object of the vue instance from inside the methods

A

just use this.keyName

ie

new Vue {
  el: '#element',
  data: {key: 'value'}
  methods: {funcName: function() { return this.keyName }}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

vue: To render a link string inside an href tag

A

type v-bind:href=’varName’

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

vue: a shorthand for v-bind: is

A

just “:”

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

vue: The easiest way to include vue in your html is

A

use a script tag to the cdn and then a script tag to your app.js

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

vue: To bind any html attribute to a variable from your vue data, type

A

v-bind:attribute-name=”varName”

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

vue: to attach a js event listener to an html attribute, type

A

v-on:click=”methodName”

note: shorthand for v-on is @
i. e @mouseover=”methodName”

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

vue: You cannot not use

A

arrow functions in vue instances because they mess with the content of “this”

confirmed!

18
Q

vue: To access the index in a for loop

A

v-for=”(item, index) in arrayName”

to enumerate just use
{{index + 1}}

19
Q

vue: When looping through an array, to pass the current array item into a click event function, type

A

v-for=”item in arrayName” v-on:click=”functionName(item)”

note: pass in the alias name

20
Q

vue: The difference between v-show and v-if is that

A

v-show uses css to hide and show stuff, and v-if injects html

21
Q

vue: The js “event” object is

A

automatically passed into event functions, without needing to pass it in.

v-on:change=”functionName”

methods: {
  functionName: function() {
    return event.target.value
  }
}

note: Unlike vanilla js or jquery

22
Q

vue: To use a computed property (where the you receive the return of a function instead of a data element), type

A
computed: {
  functionName: function() {
    return "string"
  }
}
23
Q

js: The best way to filter out particular values from an array is

A

resultVar = arrayName.filter(item => item < 5)

24
Q

js: To use a list comprehension in JS, you can basically

A

use a .filter and then a .map

25
Q

vue: Computed properties are different than methods because

A

they automatically update when their variables change, while methods need to be called.

Computed properties are cached, and dont run again unless their variables change, so it is more performant.

26
Q

vue: To use a conditional class and a variable as a class at the same time, type

A

v-bind:class=”[ {class-name: boolVar}, classVar]”

27
Q

vue: To tie an inputs value to a variable, type

A

v-model=”varName”

28
Q

vue: To use a style with a dash like border-radius in the template, you must

A

camelcase it

v-bind:style=”{borderRadius:’15px’}”

29
Q

vue: computed properties do not allow you to

A

pass in an argument in the template

30
Q

vue: The proper way mentally to make a vuejs interface is

A

first make the html and css in every state so you can think just about style
then split up the elements into components
then build the vue logic

31
Q

vue: To send a request after the vue loads, put the fetch inside

A

mounted: function () {
fetch()…
}

note: this goes outside the methods objects, not inside.

32
Q

to easily serialize a qs to json, type

A

from django.core import serializers
from django.http import HttpResponse

    qs = Noot.objects.all()
    qs_json = serializers.serialize('json', qs)
    return HttpResponse(qs_json, content_type='application/json')
33
Q

make sure not to

A

put semi colons inside inline styles values.

34
Q

Json data should always be sent as the method

A

POST, because sometimes the body is ignored on get requests.

35
Q

in a v-for, to render the items data into an html attribute i.e. data-target = “” you must

A

v-bind:data-target=”item.value”

36
Q

mouseover is better than mouseenter because

A

mouseover has more predictable behavior on mobile.

37
Q

to hide an element until page loads so it doesnt flicker use

A

[v-cloak] {
display: none;
}

and add v-cloak to the element as an attribute

38
Q

to stop a click event from bubbling up to parent, type

A

v-on:click.stop

39
Q

Inside the vue target element, you cannot

A

use regular event listeners, like element.onchange =

must use vue version @change

40
Q

to do a for of loop and get the index as well as the item, type

A

for (let [index, item] of myArray.entries()) {

41
Q

to check is a list includes a value, type

A

myArray.includes(‘string’)

42
Q

.splice() runs

A

inplace