Vue.js

Topics related to Vue.js:

Getting started with Vue.js

Vue.js is a rapidly growing front-end framework for JavaScript, inspired by Angular.js, Reactive.js, and Rivets.js that offers simplistic user-interface design, manipulation, and deep reactivity.

It is described as a MVVM patterned framework, Model-View View-Model, which is based on the concept of two-way binding data to components and views. It is incredibly fast, exceeding speeds of other top-tier JS frameworks, and very user friendly for easy integration and prototyping.

Data Binding

Components

In Component(s):

props is an array of string literals or object references used to pass data from parent component. It can also be in object form when it is desired to have more fine grained control like specifying default values, type of data accepted, whether it is required or optional

data has to be a function which returns an object instead of a plain object. It is so because we require each instance of the component to have its own data for re-usability purpose.

events is an object containing listeners for events to which the component can respond by behavioral change

methods object containing functions defining the behavior associated with the component

computed properties are just like watchers or observables, whenever any dependency changes the properties are recalculated automatically and changes are reflected in DOM instantly if DOM uses any computed properties

ready is a Vue instance's life-cycle hook

Lifecycle Hooks

Custom Filters

List Rendering

Custom Directives

Computed Properties

Data vs Computed Properties

The main use-case difference for the data and computed properties of a Vue instance is dependent on the potential state or probability of changing of the data. When deciding what category a certain object should be, these questions might help:

  • Is this a constant value? (data)
  • Does this have the possibility to change? (computed or data)
  • Is the value of it reliant on the value of other data? (computed)
  • Does it need additional data or calculations to be complete before being used? (computed)
  • Will the value only change under certain circumstances? (data)

Mixins

Props

camelCase <=> kebab-case

When defining the names of your props, always remember that HTML attribute names are case-insensitive. That means if you define a prop in camel case in your component definition...

Vue.component('child', {
    props: ['myProp'],
    ...
});

...you must call it in your HTML component as my-prop.

Vuex

Conditional Rendering

It is very important to remember the difference between v-if and v-show. While their uses are almost identical, an element bound to v-if will only render into the DOM when it's condition is true for the first time. When using the v-show directive, all elements are rendered into the DOM but are hidden using the display style if the condition is false!

Slots

Important! Slots after render don't guarantee order for positions for slots. Slot, which was the first, may have a different position after render.

Events

VueJS + Redux with Vua-Redux (Best Solution)

Dynamic Components

<component> is a reserved component element, don't be confused with components instance.

v-bind is a directive. Directives are prefixed with v- to indicate that they are special attributes provided by Vue.

Watchers

Modifiers

Plugins

In most cases you will need to explicitly tell Vue to use a plugin

// calls `MyPlugin.install(Vue)`
Vue.use(MyPlugin)

To pass options

Vue.use(MyPlugin, { someOption: true })

Polyfill "webpack" template

The configurations described above, the example using a non-sstandardised function will work on "internet explorer" and npm test will pass.

Using "this" in Vue

Custom Components with v-model

To have v-model on a component you need to fulfil two conditions.

  1. It should have a prop named 'value'
  2. It should emit an input event with the value expected by the parent components.

<component v-model='something'></component>

is just syntactic sugar for

<component
    :value="something"
    @input="something = $event.target.value"
>
</component>

Event Bus

Use vuex if your application has a lot of components requiring the data of each other.

vue-router

Vue single file components

The array change detection caveats