KEMBAR78
Don't Over-React - just use Vue! | PPTX
DON'T OVER-REACT - JUST
USE VUE!
Raymond Camden
mostly sorry ;)
WHO AM I?
Raymond Camden
Developer Advocate for IBM
Blogging at
raymondcamden.com
Tweeting at
raymondcamden
WHY VUE?
SIMPLE
NO BUILD PROCESS
SCALABLE
QUICK VUE
FACTS
Created by Evan You
(@youyuxi)
Released in February of
2014
Currently is version 2.5.13
Main site: vuejs.org
GitHub:
https://github.com/vuejs
WHAT DOES VUE DO?
Two-way binding between your DOM and JavaScript
Template Language (aka Declarative Rendering)
And I know I said this - but it does more. A lot more.
INSTALLATION
npm install
cli install
Download from site
Copy and paste a script tag FTW!!!!!1!
<SCRIPT> STYLE
<script src="https://unpkg.com/vue"></script>
WRITE SOME CODE!
Identify where you're going to render stuff
Setup some data
Render that data
Add events (ie on this do that) and other fancy stuff
$('#somediv').html('woot');
$('#yetanotherdiv').html('<b>This is awesome</b>');
$('#someotherdiv').val(2);
Willy Nilly DOM Manipulation
Defining Vue's Place...
EXAMPLES codepen.io/collection/XzN
gxR/
SOME CODE...
SOME MORE CODE...
CODE PEN: FIRST DEMO
TEMPLATE DIRECTIVES -
CONDITIONALS
TEMPLATE DIRECTIVES -
LOOPS
WORKING
WITH FORM
FIELDS
v-model links to data field
Works in all kinds of form fields
CODE PEN: FOURTH DEMO
EVENTS
v-on:click=“something”
Defined in methods block of Vue
instance
Easy to do modifiers (v-
on:submit.prevent)
@click=“something”
CODE PEN: FIFTH DEMO
ATTRIBUTE BINDING
v-bind:attribute=“value”
:attribute=“value”
v-bind:style="{bgcolor:curColor, font-style:textStyle}"
v-bind:class="{highlighted:isActive, color:appStatus}"
CODE PEN: SIXTH DEMO
COMPUTED PROPERTIES
Virtual properties
Property X is based on real data A and B
Defined in the computed part of the Vue instance
EXAMPLE (BEFORE)
EXAMPLE (AFTER)
CODE PEN: SEVENTH DEMO
VUE LIFECYCLE EVENTS
Events that occur while a Vue instance is doing stuff
beforeCreate, created, beforeMount, mounted, beforeUpate, updated,
activated, deactivated, beforeDestroy, destroyed, errorCaptured
https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
EXAMPLE
CODE PEN: EIGHTH DEMO
LET'S TAKE A
QUICK BREAK...
FULL EXAMPLE: FORM VALIDATION
Do I need to explain this?
Check on submit, report on top
More examples: https://vuejs.org/v2/cookbook/form-validation.html
FULL EXAMPLE: AJAX SEARCH
Accept user input
Send to remote API...
Render responses
COMPONENTS
Re-usable objects of awesome-ness
Template + Logic + Style = Component
Also solves one of HTML's most glaring problems...
<nicolas-cage>
EXAMPLE
EXAMPLE
CODE PEN: NICOLAS-CAGE
COMPONENT EXAMPLES
Google Static Maps: https://www.npmjs.com/package/vue-static-
map
Bootstrap: https://bootstrap-vue.js.org/
Vuetify: https://vuetifyjs.com/en/
MORE COMPONENT STUFF
You can pass data in from the parent
You can listen for events from the component
Slots
SLOT EXAMPLE
<mything thankyou="Hey buddy, thank you for doing that thing. I
appreciate it. Here's a kitten."></mything>
<mything>
<div slot="thankyou">
Hey, I want to <i>really</i> thank you for taking
the time to do whatever. We here at Mega Corp truly
care that you took the time. Oh, and here, please
take a kitten!
</div>
</mything>
ROUTING
Not a part of Vue
Official library: vue-router (https://router.vuejs.org)
"If I'm at location /foo, I want to do Foo"
"if I'm at location /goo, I want to do Goo"
EXAMPLE
(FROM THE
DOCS)
EXAMPLE
(STILL FROM
THE DOCS)
CODE PEN: EXAMPLE OF ROUTING IN VUE
FULL EXAMPLE: MASTER/DETAIL
First page - list of data
Second page - detail
STATE MANAGEMENT
Solves a problem you may not have!
One component, one set of data = easy
Two components, two set of data = mostly easy
Many components, one set of data = um....
VUEX
(Another) library for Vue (deeply integrated)
"Store"
Components can read from the store
Components cannot change data in the store
VUEX EXAMPLE
CODE PEN: STOCK GAME
THE CLI
Scaffolding tool
Focused on SPAs
https://github.com/vuejs/vue-cli
Supports Single File Components
SINGLE FILE
COMPONENT
S
WALKTHROUGH
BUT WAIT –
THERE’S
MORE!
EVEN MOAR!!!
Devtools Extension (Chrome, Firefox, Electron, Apple Keynote
Browser)
 https://github.com/vuejs/vue-devtools
Nuxt (nuxtjs.org)
Sarah Drasner on CSS-Tricks: https://css-tricks.com/intro-to-vue-1-
rendering-directives-events/
My Stuff: https://www.raymondcamden.com/tags/vuejs
ANY
QUESTIONS?
Carol is judging your
questions...

Don't Over-React - just use Vue!

Editor's Notes

  • #5 vue vs vue.js
  • #6 Approachable
  • #7 Easy to add to existing sites
  • #10 Let me stress - VUE DOES MORE THEN THIS! When I start learning something I will intentionally ignore things that I think I'm not quite ready for yet, so when I first started, Vue did two things for me. Two-way binding - not terribly exciting but really useful. So if I want to put a form field on a page and know when it changes, or I want to set it based on some condition or an Ajax load, Vue makes that easy. By template language (and the docs call it Declarative Rendering), I basically have a way of saying that if I have a JS variable called name and the value is ray, I want to show that on the page. That's not terribly exciting, but it goes very deep. Instead of a simple variable name I could have an array of names. Vue has a way to render that. WHat if name was empty of not yet defined? Vue provides conditionals. So if you've ever used or heard of Jade (now called Pug), Handlebars, Mustache, etc, than Vue has this baked in.
  • #19 code pen
  • #20 code pen
  • #26 demo app.cats.push