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”