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

Get More Done with Vue.js 2019

Get More Done with Vue.js 2019

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 to use it to build a real world application. We’ll also look at its simplicity, flexibility, performance and developer tools and see how they compare with other modern JavaScript frameworks, like React and Angular. By the end of the session, you’ll see how Vue's simplicity and flexibility combined with its performance and developer experience can help you get more done faster.

Jonathan Kemp

October 04, 2019
Tweet

More Decks by Jonathan Kemp

Other Decks in Programming

Transcript

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

    Get started with Vue • It’s flexible • Performance: Getting the most out of Vue • Community/Resources
  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. DIRECTIVES v-show • v-if • v-else • v-for • v-on

    • v-bind https://vuejs.org/v2/api/#Directives
  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 <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>
  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. 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); } } });
  11. COMPONENTS • Use Vue’s component system to build larger applications.

    • Components are small, reusable and composable • Makes building powerful web applications simple. (Similar to React)
  12. 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>
  13. 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>
  14. VUE • Does not require a compiler • Anyone can

    start using it with ES5 • Official documentation written in ES5 • Get started with a single script tag
  15. REPLACING JQUERY WITH VUE.JS: NO BUILD STEP NECESSARY Sarah Drasner

    https://www.smashingmagazine.com/2018/02/jquery-vue-javascript/
  16. REPLACING JQUERY WITH VUE • Capturing User Inputs • Toggling

    Classes • Hiding And Showing • Submitting A Form
  17. VUE-CLI • A simple CLI for scaffolding Vue.js projects with

    pre-configured build setups. • Pulls down templates from the vuejs-templates organization on GitHub that provide development tooling setups. • Get started building apps as fast as possible.
  18. CODESANDBOX • CodeSandbox is an online editor that helps you

    create web applications, from initial prototype to deployment. • Start a project with Vue, preview it in the browser, all without touching command line tools or dealing with any config files. • Afterwards, you can download your project, export it to GitHub, share it or even deploy it.
  19. VUE-LOADER • Author Vue components in a format called Single-File

    Components • Allows using webpack loaders for each part of a Vue component (ES2015) • Converts any encountered asset URLs into webpack module requests. • Simulate scoped CSS for each component • Hot reloading
  20. RENDER FUNCTIONS • For those cases where you need the

    full programmatic power of JavaScript, Vue allows you to create HTML components using JavaScript via a render function. • You can use JSX via a Babel plugin. • With JSX, you can get back to a syntax that’s much closer to templates.
  21. VUE RENDER FUNCTION render (h) { return h( 'div', {

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

    <div id='my-id'>, { this.msg } </div> ); }
  23. CSS-IN-JS AND VUE • Many of the popular CSS-in-JS libraries

    support Vue • Styling in Vue is through more familiar style tags in single-file components. • Optional scoped attribute automatically scopes this CSS to your component
  24. SINGLE FILE COMPONENTS • If your project is more complex,

    like a Single Page Application, you can create single-file components with Vue. • Single file components are components contained in a single file with a .vue extension • Compiled with a build tool like Webpack or Browserify.
  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. SERVER-SIDE RENDERING • Not exactly trivial but it is possible

    to do server-side rendering with Vue. • The Vue guide has excellent documentation that walks you through this step-by-step. • https://ssr.vuejs.org/
  27. NUXT.JS • Aims to simplify server-side rendering in your Vue

    projects. • You can even use it as a static site generator • Available on CodeSandbox
  28. WEEX • A project similar to React Native that uses

    Vue to build native applications for iOS and Android. • With Weex, you can create native mobile UI using components written in Vue.js.
  29. ANIMATION • Vue provides different ways to apply transition effects

    when items are inserted, updated, or removed from the DOM. • Integrate third party CSS animation libraries or JS animation libraries or use JavaScript directly. • Automatically apply classes for CSS transitions and animations.
  30. EXTEND VUE • Register your own custom directives for accessing

    the DOM on your HTML elements. • Distribute reusable functionalities for Vue components with mixins. • Plugins are available to add global-level functionality.
  31. VUEX • Designed primarily use with for large and complex

    applications with many components. • Inspired by the functional, compile-to-JavaScript library elm. • Often compared to Redux, another state management library that is also inspired by elm.
  32. GRIDSOME • Fast - Code splitting, asset optimization, progressive images,

    and link prefetching out of the box. • Modern build tools - Babel, PostCSS, Webpack, and friends • Vue.js for frontend
  33. VUEPRESS • Minimalistic static site generator with a Vue-powered theming

    system • Officially supported • Powered by Vue, Vue Router and webpack • Still a work in progress
  34. VUETIFY • Material design based Vue CLI packages to get

    your project started in no time • Supports SSR, SPA, PWA and standard HTML pages.
  35. QUASAR • SPAs (Single Page App) • SSR (Server-side Rendered

    App) • PWAs (Progressive Web App) • Mobile Apps (Android, iOS, …) through Apache Cordova • Multi-platform Desktop Apps (using Electron)
  36. QUASAR • Material Design 2.0 • Fast Web Components •

    Best practices integrated by default • Progressively migrate your existing project
  37. PERFORMANCE • Performance usually means two things, how fast our

    app loads and how fast it responds to our interactions. • Vue actually does well in both categories of performance, and it compares favorably with other popular frameworks, like React.
  38. OPTIMIZE FOR PERFORMANCE • Vue is in development mode by

    default. • If you are directly including Vue via a script tag, make sure to use the minified version (vue.min.js) for production. • When using a build tool, enable Vue’s production mode so that warnings are stripped out during the build.
  39. PRE-COMPILING TEMPLATES • Pre-compiling Vue templates will help them render

    faster than using in-DOM templates or in-JavaScript template strings. • The easiest way to pre-compile templates is to use Single-File Components. • The build setup automatically performs pre-compilation for you.
  40. ASYNC COMPONENTS • Load a component from the server when

    it’s actually needed. • Use async components together with Webpack’s code-splitting feature. • Vue will cache the result for future re-renders.
  41. SERVER-SIDE RENDERING • Downloading a single, pre-rendered HTML file is

    more performant than code splitting and async components. • We can achieve this in a Vue.js app with server-side rendering.
  42. PRERENDERING • Generates static HTML files from a single page

    application for specific routes at build time. • Prerendering can improve SEO just as well as SSR, with significantly less setup. • Prerendering can be more performant than SSR.
  43. 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' ] ) ] }
  44. PRERENDERING • Run your app before deploying it, capture the

    page output and replace your HTML files with this captured output. • It’s pretty much the same concept as SSR except it’s done pre- deployment in your development environment, not a live server. • Pre-rendering is typically performed by running your app in a headless browser.