Slide 1

Slide 1 text

1 WHY VUE.JS? “The Progressive JavaScript Framework” Introduction to Vue.js Jonathan Goode

Slide 2

Slide 2 text

2 . 1 WHAT IS VUE.JS? Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces The core library is focused on the view layer only The library was created by who released v1 on 26 October 2015 The project is permanently backed by pledgers on $7,572 (~£6,145) per month Evan You Patreon.com

Slide 3

Slide 3 text

2 . 2 WHO USES VUE? Rank Site Detections 1st laravel.com 49,476 2nd laracasts.com 29,185 3rd gitlab.com 26,522 8th codeship.com 3,069 Detections by Wappalyzer in the last 7 days INTERNATION ADOPTION China: Alibaba and Baidu, Japan: Nintendo and UK: Sainsbury's

Slide 4

Slide 4 text

2 . 3 USING VUE Getting started with Vue.js is extremely easy Its source code is very readable, and the documentation is the only tutorial you will need You don't need external libraries You can use it with or without jQuery You won't even need to install any plugins, though many are available

Slide 5

Slide 5 text

2 . 4 USING VUE Hooking Vue up to existing code is very straightforward Vue makes no assumptions about your code It really only assumes that your data will change Real-life usage is as simple as the docs demonstrate it to be

Slide 6

Slide 6 text

3 . 1 PERFORMANCE Vue.js 2.0 was released on Sep 30 - current release is v2.0.3 - 16kb min+gzip Based on , lower is better 3rd party benchmark

Slide 7

Slide 7 text

3 . 2 VUE.JS 2.0 The rendering layer has been rewritten using a light-weight Virtual DOM implementation forked from . On top of that, Vue's template compiler is able to apply some smart optimizations during compilation, such as analyzing and hoisting static sub trees to avoid unnecessary diffing on re- render. The new rendering layer provides significant performance improvements compared to v1, and makes Vue 2.0 one of the fastest frameworks. In addition, it requires minimal effort in terms of optimization because Vue's reactivity system is able to precisely determine components that need to be re-rendered in a large and complex component tree. snabbdom

Slide 8

Slide 8 text

4 . 1 VUE AND CONDITIONAL LOGIC V‐IF / V‐ELSE // JavaScript var example = new Vue({ el: '.example', data: { cond: (1 > 0), }, // true });
Yes
No

Slide 9

Slide 9 text

4 . 2 V‐SHOW // JavaScript var example = new Vue({ el: '.example', data: { cond: (1 > 0), }, // true });
Yes
No

Slide 10

Slide 10 text

4 . 3 WITH A TEMPLATE

Title

Paragraph 1

Paragraph 2

=

Title

Paragraph 1

Paragraph 2

Slide 11

Slide 11 text

4 . 4 V‐FOR // JavaScript var example = new Vue({ el: '.example', data: { items: { message: 'Foo' }, { message: 'Bar' }, }, });
  • {{ item.message }}

Slide 12

Slide 12 text

4 . 5 V‐FOR USING AN OBJECT // JavaScript var example = new Vue({ el: '.example', data: { object: FirstName: 'Jonathan', LastName: 'Goode', Age: 30, }, });
  • {{ $key }}: {{ value }}

Slide 13

Slide 13 text

4 . 6 V‐FOR USING A RANGE // JavaScript var example = new Vue({ el: '.example', });
  • {{ n }}

Slide 14

Slide 14 text

4 . 7 V‐FOR USING A FILTER What will the output be? // JavaScript var example = new Vue({ el: '.example', data: { array: [2, 4, 6, 8, 10,], }, });
  • {{ n }}

Slide 15

Slide 15 text

5 VUE AND EVENT HANDLING Link Link // Modifiers Link Link Link

Slide 16

Slide 16 text

6 VUE AND LARAVEL // JavaScript ­ for Laravel (requires jQuery) Vue.http.headers.common['X­CSRF­TOKEN'] = $('meta[name="csrf­token"]').attr('content'); // PHP ­ escape Blade syntax @{{ item.message }} (Recommended Combination)

Slide 17

Slide 17 text

7 INSTALLING VUE package.json "dependencies": { "vue": "*" } Run npm $ npm install

Slide 18

Slide 18 text

8 VUE EXPLAINED HELLO WORLD EXAMPLE ⇲ The data for the view goes in an object called data This can get there and look however you want Functions are written as callbacks that go into a methods object They can do or return whatever you want var journal = new Vue({ el: '.journal', data: { message: 'Hello World' }, methods: { }, });
{{ message | json }}

Slide 19

Slide 19 text

9 INPUT COUNTER EXAMPLE ⇲ // JavaScript new Vue({ el: '.question­text', data: { questions: [{ question_text: '', }], }, methods: { getLength: function(key){ return mb_strlen(this.questions[0][key]); }, }, }); Characters: / 500

Slide 20

Slide 20 text

10 . 1 VUE DIRECTIVES Custom directives provide a mechanism for mapping data changes to arbitrary DOM behaviour "seiyria‐bootstrap‐slider": "7.0.3" Vue.directive('slider', { bind: function(){ /* do preparation work */ var vm = this.vm; var key = this.expression; var slider = $(this.el).slider() .on('change', function(ev){ vm.$set(key, ev.value.newValue); }) .data('slider'); }, update: function(val){ /* do something based on initial/updated value */ val = parseFloat(val); if(!isNaN(val)){ $(this.el).slider('setValue', val); } }, unbind: function(){ /* do clean up work */ }, });

Slide 21

Slide 21 text

10 . 2 SLIDER EXAMPLE ⇲ // JavaScript new Vue({ el: '.form­alerts', data: alerts: [{ id: '', alert_message: '', alert_time: '' }], });

Slide 22

Slide 22 text

11 VUE PLUGINS Provides services for making web requests and handling responses using an XMLHttpRequest or JSONP The HTTP client for Vue.js Centralised State Management for Vue.js Similar to (Re)Flux for React Bootstrap components built with Vue.js No jQuery, bootstrap.js, or any third party plugins required VueResource VueRouter VueX VueStrap

Slide 23

Slide 23 text

12 MORE RESOURCES https://vuejs.org https://github.com/vuejs/vue Vue.js DevTools - Chrome Extension