Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vue.js @ A taste of modern Frontend

maoosi
September 27, 2016

Vue.js @ A taste of modern Frontend

Introduction to Vue.js and modern Frontend approach.
---
Melbourne Vue.js Meetup: http://www.meetup.com/vuejs-melbourne/
Google Slides: http://bit.ly/2cSsuan
Presentation by: http://sylvainsimao.fr

maoosi

September 27, 2016
Tweet

More Decks by maoosi

Other Decks in Programming

Transcript

  1. What if I told you, that HTML5 is taking control

    ? • Flash banners become HTML5 banners • Games become browser games • Native mobile apps become hybrid apps • Software become web applications
  2. Advantages of using a Framework • Don’t reinvent the wheel

    • Do more with less code • Save time (and money) • Brings order out of chaos
  3. DOM-Driven approach is problematic If we rename an element, or

    if we change the html structure, the code will be broken. Code complexity.
  4. Data-Driven approach one way to reduce complexity (eg. with Vue.js)

    We can change the html structure and rename elements without breaking the code. Minimalist code. v-model = data-binding | v-if = conditional rendering
  5. React Angular 2 Vue.js Text interpolation { message } {{

    message }} {{ message }} Bind text content <div textContent={message}> <div [textContent]="message"> <div v-text="message"> DOM add/remove {shouldShow && <div />} <div *ngIf="shouldShow"> <div v-if='shouldShow'> Repeat items.map(item => <div key={item.id} /> ) <div *ngFor="let item of items"> <div v-for="item in items"> Bind event handler <button onClick={clicked}> <button (click)="clicked()"> <button v-on:click="clicked"> Define component ES6 class Polyglot extends React.Component @Component({})class Polyglot {} class Polyglot extends Vue Define component ES5 React.createClass({}) ng.core.Component({}).Class({}) Vue.extend({}) Two-way binding (native) not supported <input [(ngModel)]="foo" /> <input v-model="foo" /> Two-way binding (components) not supported <Child [(foo)]="bar" /> <child :foo.sync="bar"></child> Source: Front-end Hyperpolyglot
  6. The State Of JavaScript: Survey about Front-End Frameworks Over 3000

    responses from worldwide Front-End developers.
  7. So what’s Vue.js ? • Open-source progressive Framework • First

    release in Feb. 2014 • Created by Evan You (Meteor / Google Creative Lab)
  8. Vue.js - Today • ~28,053 stars on GitHub • ~150k

    downloads/month (NPM only) • $8,000+ monthly support from the community
  9. DOM Problems with the DOM • Re-rendering entire chunks of

    DOM is expensive and disruptive • Ensuring that you keep the DOM in sync with the state is tedious and error-prone
  10. Declarative & Reactive Rendering View User Input State Render View

    is just a declarative mapping from the state State should be the single source of truth
  11. Virtual DOM Render Function Template compile Virtual DOM Tree Actual

    DOM Tree create render Watcher track dependencies
  12. ...vue.js is fast Vanilla JavaScript Vue 2.0.0-beta.1 React 15.3.0 Angular

    2.0.0-rc.4 1x 1.29x 1.74x 1.97x Based on independent 3rd party comprehensive rendering benchmark
  13. • Imported as a ES6 module (easily testable) • Collocation

    of Template, Logic & Style • Just use what you already know: HTML, CSS & JavaScript • Embedded preprocessor support: Sass, Less, Pug, Stylus • Component-scoped CSS with a single attribute (no conflicts) Single File Vue Components
  14. Vue.js offers a rich ecosystem VueX (State management) Vue-Resource (HTTP

    requests) Vue-Router (Routing) Vue-CLI (Command line scaffolding)
  15. Agencies will love it ... • Small learning curve and

    semantic • Pre-processor agnostic (Jade/Pug, Sass, Stylus...) • Server-side rendering (SEO / Javascript disabled) • Stable, maintained, and tested • Vue.js 2.x is (almost) retro-compatible