Vue.js

The Vue Instance

new Vue({
  el: '#app',
  data() {
    return {
      firstName: 'Aliaksandr',
      lastName: 'Shcharbak'
    };
  }
});

<div id="app">
  <span>First Name: {{ firstName }}</span>
  <span>Last Name: {{ lastName }}</span>
</div>
<a v-bind:href="url"> ... </a>

<a :href="url"> ... </a>
<a v-on:click="doSomething"> ... </a>

<a @click="doSomething"> ... </a>

<p v-if="seen">Now you see me</p>
<ul id="example-1">
  <li v-for="item in items">
    {{ item.message }}
  </li>
</ul>

Computed Properties. Watchers

<div id="example">
  <p>Original message: "{{ message }}"</p>
  <p>Computed reversed message: "{{ reversedMessage }}"</p>
  <p>Reversed message from method: "{{ reversedMessageMethod() }}"</p>
</div>

var vm = new Vue({
  el: '#example',
  data: {
    message: 'Hello'
  },
  computed: {
    reversedMessage: function () {
      return this.message.split('').reverse().join('');
    }
  },
  methods: {
    reverseMessageMethod: function () {
      return this.message.split('').reverse().join('');
    }
});

Components. Event Handling

<div id="counter-event-example">
  <p>{{ total }}</p>
  <button-counter v-on:increment="incrementTotal"></button-counter>
  <button-counter v-on:increment="incrementTotal"></button-counter>
</div>

Vue.component('button-counter', {
  template: '<button v-on:click="incrementCounter">{{ counter }}</button>',
  data: function () {
    return {
      counter: 0
    }
  },
  methods: {
    incrementCounter: function () {
      this.counter += 1
      this.$emit('increment')
    }
  },
})

new Vue({
  el: '#counter-event-example',
  data: {
    total: 0
  },
  methods: {
    incrementTotal: function () {
      this.total += 1
    }
  }
})

Single File Components

Reactivity

Additional Features

  • Virtual DOM
  • Class and Style Bindings
  • Event Modifiers
  • Key Modifiers
  • Slots
  • <template>
  • Render function and JSX
  • TypeScript support
  • Vue-router
  • Vuex
  • Vue-cli
  • Vue-devtools
  • How mature are the frameworks / libraries?
  • Are the frameworks likely to be around for a while?
  • How extensive and helpful are their corresponding communities?
  • How easy is it to find developers for each of the frameworks?
  • What are the basic programming concepts of the frameworks?
  • How easy is it to use the frameworks for small or large applications?
  • What does the learning curve look like for each framework?
  • What kind of performance can you expect from the frameworks?
  • Where can you have a closer look under the hood?

Q&A

Vue

By alexandrscherbak