vuejs Flashcards
vue: a directive is an
expression you write in the template starting with v-
vue: To interpolate a variable just once (so it wont be reactive)
add v-once tag attribute and put {{varName}} into middle of tag
vue: The directive for showing or hiding an element based on the boolean value of a variable
v-if=”boolVar”
Note:
v-else for opposite
vue: To render text or html using a directive
v-text or v-html
vue: To make a for loop directive
v-for=”item in myArray” and to get attribue {{item.name}}
vue: To make a class conditional on a context variable
v-bind:class=”{class-name: boolVar}”
note: the varName should return true or false
vue: To make the value of css in the style attribute be the value of a variable
v-bind:style=”{color: varName}”
vue: To register a component, type
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>
vue: To render a component in the template
-component-name> -/component-name>
vue: To make a vue widget on your page, type
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.
vue: To get data from the data object of the vue instance from inside the methods
just use this.keyName
ie
new Vue { el: '#element', data: {key: 'value'} methods: {funcName: function() { return this.keyName }} }
vue: To render a link string inside an href tag
type v-bind:href=’varName’
vue: a shorthand for v-bind: is
just “:”
vue: The easiest way to include vue in your html is
use a script tag to the cdn and then a script tag to your app.js
vue: To bind any html attribute to a variable from your vue data, type
v-bind:attribute-name=”varName”
vue: to attach a js event listener to an html attribute, type
v-on:click=”methodName”
note: shorthand for v-on is @
i. e @mouseover=”methodName”
vue: You cannot not use
arrow functions in vue instances because they mess with the content of “this”
confirmed!
vue: To access the index in a for loop
v-for=”(item, index) in arrayName”
to enumerate just use
{{index + 1}}
vue: When looping through an array, to pass the current array item into a click event function, type
v-for=”item in arrayName” v-on:click=”functionName(item)”
note: pass in the alias name
vue: The difference between v-show and v-if is that
v-show uses css to hide and show stuff, and v-if injects html
vue: The js “event” object is
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
vue: To use a computed property (where the you receive the return of a function instead of a data element), type
computed: { functionName: function() { return "string" } }
js: The best way to filter out particular values from an array is
resultVar = arrayName.filter(item => item < 5)
js: To use a list comprehension in JS, you can basically
use a .filter and then a .map