Why Vue - JS?: Finding A Javascript Framework That Just Worked
Why Vue - JS?: Finding A Javascript Framework That Just Worked
Brian Wells
@brianjwells
Who am I?
● Senior Lab Software Developer at Riverbed
● Recently moved to Nashville area in May
● Currently use Vue.js in production
● Working remotely
Angular, Ember, React, etc
https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4
Lessons I’ve Learned
Lessons I’ve Learned
● You’ll embrace a framework once it solves a problem you have
● There will always be a popular new framework
● Choose one that is stable and master it
● Don’t be afraid to tinker first
● Never stop learning
The progressive framework
The progressive framework
@vuejs
https://twitter.com/vuejs/status/753636851504799744
The progressive framework
1. The Core Vue.js Framework
2. Components
3. HTTP Resources
4. Client-Side Routing
5. State management
The progressive framework
http://blog.evanyou.me/2015/12/20/vuejs-2015-in-review/
Let’s Get Started
The Core Vue.js Framework
● Reactive data binding User Input
this.setState()
// Knockout
ko.observable()
The Core Vue.js Framework
Vue Instance
Event Listeners
View State
Directives (1.x)
Virtual DOM (2.0)
● Directives
○ v-model="message"
new Vue({
○ v-bind:href="message.url" el: '#app',
■ :href="message.url" data: {
message: 'Hello Vue.js!'
○ v-on:click="sendMessage"
}
■ @click="sendMessage" })
The Core Vue.js Framework <div id="app">
<button @click="b">Increment</button>
a={{ a }}
● Methods </div>
○ methods: { ... }
new Vue({
● Handle native DOM events el: '#app',
○ @click or v-on:click data: {
a: 1
● Automatic event listeners },
methods: {
○ // jQuery example
b: function (event) {
$('#button').on('click', // `this` points to the vm instance
function (event) { this.a = this.a + 1
}
...
}
}); })
The Core Vue.js Framework <div id="app">
a={{ a }} b={{ b }}
● Computed properties </div>
○ computed: { ... }
new Vue({
● Replaces binding expressions el: '#app',
data: {
○ {{ ok ? 'YES' : 'NO' }}
a: 1
● Computed setter },
computed: {
○ computed: { // a computed getter
b: { b: function () {
// `this` points to the vm instance
get: function () { ... },
return this.a + 1
set: function (newValue) { ... } }
} }
})
}
The Core Vue.js Framework
● Class and style bindings
○ :class or v-bind:class <div class="static" :class="{ 'class-a': isA }">
...
○ :style or v-bind:style
</div>
● Conditional rendering
○ v-if="hasMessages"
<h1 v-if="hasMessages">Yes</h1>
○ v-show="hasMessages" <h1 v-else>No</h1>
○ v-else
<h1 v-show="hasMessages">Yes</h1>
<h1 v-else>No</h1>
<div id="app">
The Core Vue.js Framework <ul>
<li v-for="todo in todos">
{{ todo.text }}
● JSON data format
</li>
○ var object = { ... } </ul>
</div>
● List rendering
○ v-for="todo in todos"
new Vue({
○ todos: [ {...}, {...}, {...} ]
el: '#app',
data: {
todos: [
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue.js' },
{ text: 'Build Something Awesome' }
]
}
})
Components
Components
Nav
Content Sidebar
● Small
Item
● Self-contained
● Often reusable
Components
<div id="app">
<app-nav></app-nav>
<app-content>
● Custom DOM elements <example></example>
</app-content>
○ <my-component></my-component>
</div>
● Native application
Home
App
/movies/1
https://rc.vuejs.org/
Vue.js In Practice
Project Idea
● AirPlay movies from server
● Simple clean interface
● JSON-API 1.0
● Laravel
● Vue.js
Live Demo
Additional Resources Get the slides: https://goo.gl/yxU0w7
Books
● You Don’t Know JS - Book Series
● JavaScript: The Good Parts