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

Get More Done with Vue.js 2017

Jonathan Kemp
September 21, 2017

Get More Done with Vue.js 2017

Vue.js is a framework for building user interfaces that’s designed to be simple and flexible with a heavy focus on performance. In this session, you’ll learn what Vue.js is and how its simplicity and flexibility combined with its performance and developer experience can help you get more done.

Jonathan Kemp

September 21, 2017
Tweet

More Decks by Jonathan Kemp

Other Decks in Technology

Transcript

  1. GET MORE DONE WITH VUE.JS • What is it? •

    Easy to get started • It’s flexible • It’s fast • Developer Tools
  2. TEMPLATES <div id="app"> Hello {{name}}! </div> var app = new

    Vue({ el: '#app', data: { name: 'Jonathan' } });
  3. TEMPLATES <div id="app"> Hello {{name}}! </div> var app = new

    Vue({ el: '#app', data: { name: 'Jonathan' } });
  4. DIRECTIVES <div id="app"> <ol> <li v-for="item in list"> {{ item

    }} </li> </ol> </div> var app = new Vue({ el: '#app', data: { list: ['One', 'Two', 'Three', 'Four'] } });
  5. DIRECTIVES <div id="app"> <ol> <li v-for="item in list"> {{ item

    }} </li> </ol> </div> var app = new Vue({ el: '#app', data: { list: ['One', 'Two', 'Three', 'Four'] } });
  6. EVENT LISTENERS <div id="app"> <h3>TODO List</h3> <form id="todo-form"> <input id="update"

    type="text" value="" /> <button type="submit" v-on:click.prevent="addTodo">Add Item</button> </form> <ol> <li v-for="item in list"> {{ item }} </li> </ol> </div>
  7. EVENT LISTENERS <div id="app"> <h3>TODO List</h3> <form id="todo-form"> <input id="update"

    type="text" value="" /> <button type="submit" v-on:click.prevent="addTodo">Add Item</button> </form> <ol> <li v-for="item in list"> {{ item }} </li> </ol> </div>
  8. EVENT LISTENERS var app = new Vue({ el: '#app', data:

    { list: [] }, methods: { addTodo: function () { var input = document.getElementById('update'); this.list = this.list.concat(input.value); } } });
  9. EVENT LISTENERS var app = new Vue({ el: '#app', data:

    { list: [] }, methods: { addTodo: function () { var input = document.getElementById('update'); this.list = this.list.concat(input.value); } } });
  10. COMPONENTS // Define a new component called todo-item Vue.component('todo-item', {

    template: '<li>This is a todo</li>' }) <ol> <!-- Create an instance of the todo-item component --> <todo-item></todo-item> </ol>
  11. COMPONENTS // Define a new component called todo-item Vue.component('todo-item', {

    template: '<li>This is a todo</li>' }) <ol> <!-- Create an instance of the todo-item component --> <todo-item></todo-item> </ol>
  12. REACT WITHOUT JSX Each JSX element is just syntactic sugar

    for calling 
 
 React.createElement(component, props, ...children).
  13. REACT COMPONENTS class HelloMessage extends React.Component { render() { return

    <div>Hello {this.props.name}</div>; } } ReactDOM.render(<HelloMessage name="John" />, mountNode);
  14. REACT COMPONENTS class HelloMessage extends React.Component { render() { return

    <div>Hello {this.props.name}</div>; } } ReactDOM.render(<HelloMessage name="John" />, mountNode);
  15. REACT COMPONENTS class HelloMessage extends React.Component { render() { return

    React.createElement( "div", null, "Hello ", this.props.name ); } } ReactDOM.render(React.createElement(HelloMessage, { name: "John" }), mountNode);
  16. REACT COMPONENTS class HelloMessage extends React.Component { render() { return

    React.createElement( "div", null, "Hello ", this.props.name ); } } ReactDOM.render(React.createElement(HelloMessage, { name: "John" }), mountNode);
  17. REACT OR ANGULAR 2 • JSX • Probably ES6 or

    TypeScript • Compiler/Build system
  18. VUE • Does not require a compiler • Anyone can

    start using it with ES5 • Official documentation written in ES5
  19. SIMILARITIES WITH REACT • They both use virtual DOM. •

    They both create view components that are reactive and composable. • They both focus on the core library, leaving the development of features like routing and state management to external libraries.
  20. DIFFERENCES WITH REACT • Vue’s virtual DOM implementation is a

    fork of snabbdom. • Vue libraries for state management and routing are all officially supported while React leaves this to the community.
  21. ANGULAR V1 DIFFERENCES • Vue is simpler than Angular 1

    though, in terms of API and design. • Angular 1 is also more opinionated about how you structure your applications. • Performance-wise Vue is faster than Angular 1.
  22. JSX

  23. VUE RENDER FUNCTION WITHOUT JSX render (h) { return h(

    'div', { attrs: { id: 'my-id' }, [ this.msg ] ); }
  24. VUE RENDER FUNCTION WITH JSX render (h) { return (

    <div id='my-id'>, { this.msg } </div> ); }
  25. HELLO.VUE <template> <p>{{ greeting }} World!</p> </template> <script> module.exports =

    { data: function () { return { greeting: ‘Hello’ } } } </script> <style scoped> p { font-size: 2em; text-align: center; } </style>
  26. PERFORMANCE • How fast our app loads • How fast

    it responds to our interactions
  27. VUE VS. REACT • Vue’s Virtual DOM implementation (a fork

    of snabbdom) is lighter-weight • When stateless components are used in performance-critical situations, Vue is once again faster
  28. WEBPACK (SIMPLE) // webpack.conf.js var Path = require('path') var PrerenderSpaPlugin

    = require('prerender-spa-plugin') module.exports = { // ... plugins: [ new PrerenderSpaPlugin( // Absolute path to compiled SPA Path.join(__dirname, '../dist'), // List of routes to prerender [ '/', '/about', '/contact' ] ) ] }