SlideShare a Scribd company logo
www.tothenew.com
Introduction to Vue.js
Aman K Mishra
7 September, 2017
www.tothenew.com
This is me
A learner
A NEWER (Working at TO THE NEW) for almost 3 years now
Total experience : 5 Years ( AngularJs - 1, Groovy and Grails - 2, Java -2)
Other self learnt skills : Angular 2, React.js, Node.js, MondoDB
Associate Lead - Technology
www.tothenew.com
How does minimal code look like
<script src="https://unpkg.com/vue"></script>
<div id="app">
{{ message }}
</div>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
www.tothenew.com
About Vue
Vue was created by Evan You after working for Meteor dev group and Google
Originally released in February 2014
Latest stable release : 2.4.2
Backed by Laravel and Alibaba
Evan you
www.tothenew.com
Who are using it in production
Here you can find some of people talking about their experience on using Vue.js
Here you can find detailed list of project using Vuejs
www.tothenew.com
Let’s compare : There will be blood
www.tothenew.com
Popularity in 2016
Vue.JS project got more than 25,000 stars on Github last year, it means 72 stars per
day, it's more than what any other framework got, including React and Angular.
www.tothenew.com
Size comparison
Approximation of gzipped versions
www.tothenew.com
Performance Comparison
Lower is better
www.tothenew.com
Vanilla Javascript?
?
www.tothenew.com
Comparison links
https://vuejs.org/v2/guide/comparison.html
https://about.gitlab.com/2016/10/20/why-we-chose-vue/
http://www.evontech.com/what-we-are-saying/entry/why-developers-now-compare-
vuejs-to-javascript-giants-angular-and-react.html
http://pixeljets.com/blog/why-we-chose-vuejs-over-react/
https://about.gitlab.com/2016/10/20/why-we-chose-vue/
https://hashnode.com/post/what-is-the-advantage-of-vuejs-over-angular-or-react-in-
terms-of-performance-ease-of-use-and-scalability-cit4sbaxi18xj8k53ejiuahiy
www.tothenew.com
Let’s see some code now
www.tothenew.com
Template Syntax
<span>Message: {{ msg }}</span> <span v-once>
This will never change: {{ msg }}
</span>
<div v-html="rawHtml"></div>
<div v-bind:id="dynamicId"></div>
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
<div v-bind:id="'list-' + id"></div>
var app = new Vue({
el: '#app-2',
data: {
message: 'You loaded this page on
' + new Date().toLocaleString()
}
})
www.tothenew.com
Template Syntax : Cont...
<p v-if="seen">Now you see me</p>
<a v-on:click="doSomething">
<form v-on:submit.prevent="onSubmit"></form>
<!-- full syntax -->
<a v-bind:href="url"></a>
<!-- shorthand -->
<a :href="url"></a>
<!-- full syntax -->
<a v-on:click="doSomething"></a>
<!-- shorthand -->
<a @click="doSomething"></a>
Values and methods
defined in Vue instance
www.tothenew.com
The Vue Instance
var data = { a: 1 }; // Our data object
// The object is added to a Vue instance
var vm = new Vue({
data: data
})
// These reference the same object!
vm.a === data.a // => true
// Setting the property on the instance also affects the original data
vm.a = 2
data.a // => 2
// ... and vice-versa
data.a = 3
vm.a // => 3
www.tothenew.com
The Vue Instance : Cont...
new Vue({
data: {
a: 1
},
created: function () {
// `this` points to the vue instance
console.log('a is: ' + this.a)
}
})
Are you sure about
scope of “this” here?
Other life cycle hooks :
● beforeCreate
● created
● beforeMount
● mounted
● beforeDestroy
● Destroyed
Life cycle event
www.tothenew.com
Class and Style binding
<div v-bind:class="{ active: isActive }"></div>
<div class="static"
v-bind:class="{ active: isActive, 'text-danger':
hasError }">
</div> data: {
isActive: true,
hasError: false
}
<div v-bind:class="classObject"></div>
data: {
classObject: {
active: true,
'text-danger': false
}
}
<div v-bind:style="styleObject"></div>
data: {
styleObject: {
color: 'red',
fontSize: '13px'
}
}
www.tothenew.com
Filters
<!-- in mustaches -->
{{ message | capitalize }}
<!-- in v-bind -->
<div v-bind:id="rawId | formatId"></div>
new Vue({
// ...
filters: {
capitalize: function (value) {
if (!value) return ''
value = value.toString()
return value.charAt(0).toUpperCase()
+ value.slice(1)
}
}
})
{{ message | filterA | filterB }}
Of course, Filter can be chained
Filters are JavaScript functions, therefore
they can take arguments:
{{ message | filterA('arg1', arg2) }}
www.tothenew.com
Directives
ENOUGH. What’s New?
Check this link for directives
www.tothenew.com
Conditional Rendering
<h1 v-if="ok">Yes</h1>
<h1 v-else>No</h1>
<h1 v-if="user"> {{user.username}}</h1>
<h1 v-if="user"> {{user.firstName}}</h1>
<h1 v-if="user"> {{user.lastName}}</h1>
<div v-if=”user”>
<span> {{user.username}}</span>
<span> {{user.firstName}}</span>
<span> {{user.lastName}}</span>
</div>
Code duplicacy
You just increased DOM element
count. What if it’s in loop? And this
might break css styling also.
<template v-if="ok">
<h1>Title</h1>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
</template>
An invisible wrapper. The final
rendered result will not include the
<template> element.
Angular way to do this
www.tothenew.com
Conditional Reusable elements
<template v-if="loginType === 'username'">
<label>Username</label>
<input placeholder="Enter your username">
</template>
<template v-else>
<label>Email</label>
<input placeholder="Enter your email address">
</template>
Vue tries to render elements as efficiently as possible, often re-using them instead of
rendering from scratch. Beyond helping make Vue very fast, this can have some
useful advantages. For example, if you allow users to toggle between multiple login
types:
Then switching the loginType in the code above will not erase what the user has
already entered. Since both templates use the same elements, the <input> is not
replaced - just its placeholder
If you don’t
need this, just
use attribute
“key”
key="username"
key="email"
www.tothenew.com
Computed property
<div id="example">
<p>Original message: "{{ message }}"</p>
<p>Computed reversed message: "{{
reversedMessage }}"</p>
</div>
var vm = new Vue({
el: '#example',
data: { message: 'Hello' },
computed: {
// a computed getter
reversedMessage: function () {
return this.message.split('').reverse().join('')
}
}
})
I don’t need computed
property. I can do it like this.
<p>
Reversed message: "{{ reverseMessage()
}}"
</p>
// in vue instance
methods: {
reverseMessage: function () {
return this.message.split('').reverse().join('')
}
}
Caching
www.tothenew.com
What else?
There are many more. Obviously, there are design level changes to overcome the
problem of AngularJs like watchers and digest cycle
www.tothenew.com
How do you feel so far..
So close to AngularJs and Angular2 .
Learning curve is very low
www.tothenew.com
Components - A smallest component
<div id="example">
<my-component></my-component>
</div>
// register
Vue.component('my-component', {
template: '<div>A custom component!</div>'
})
// create a root instance
new Vue({
el: '#example'
})
www.tothenew.com
Passing data to Component
Vue.component('child', {
// declare the props
props: ['myMessage'],
// just like data, the prop can be used inside templates
// and is also made available in the vm as this.message
template: '<span>{{ myMessage }}</span>'
})
<child my-message="hello!"></child>
www.tothenew.com
One way data flow
Our learning from react, data should flow top to bottom. It makes
application less error prone
props: ['initialCounter'],
data: function () {
return { counter: this.initialCounter }
}
Inside a Vue component, we achieve it as :
www.tothenew.com
Hey, I could validate props in React
www.tothenew.com
Prop Validation
Vue.component('example', {
props: {
propA: Number, // basic type check (`null` means accept any type)
propB: [String, Number], // multiple possible types
propC: { // a required string
type: String, required: true
},
propD: { // a number with default value
type: Number, default: 100
},
propF: { // custom validator function
validator: function (value) {
return value > 10
}
}
}
})
www.tothenew.com
A component with event
<div id="counter-event-example">
<p>{{ total }}</p>
<button-counter
v-on:increment="incrementTotal">
</button-counter>
<button-counter
v-on:increment="incrementTotal">
</button-counter>
</div>
Vue.component('button-counter', {
template: '<button v-on:click="incrementCounter">{{ counter
}}</button>',
data: function () {
return {
counter: 0
}
},
methods: {
incrementCounter: function () {
this.counter += 1
this.$emit('increment')
}
},
})
new Vue({
el: '#counter-event-example',
data: {
total: 0
},
methods: {
incrementTotal: function () {
this.total += 1
}
}
})
www.tothenew.com
Render function and JSX
If you are not satisfied with templates, you can use Render function and JSX also.
Check official documentation for more detail on this
www.tothenew.com
Ecosystem
Vue Router
Vuex : State management for Vue
Redux can also be integrated
Let’s explore more, visit official documentation
Vue-devtool
vue-cli
weex : For native app. Maintained by Alibaba
www.tothenew.com
!(Why should you go for Vue.js)
● Not yet used for large applications like React ?
● If you stick to your current framework, you can utilize learning of your past
projects the most
● You can also use a good %age of codebase from previous project
www.tothenew.com
Why should you go for Vue.js
Easy to kick start.
Learning curve is very low as most of concepts are reused from Angular and React
No need to learn ES6 and JSX as in case of React
Faster in comparison to other libraries
Also, smaller in size
It is expected to be more popular in 2017 and coming years
Easy integration with other popular libraries and axios, redux etc.
Ecosystem is also good. Community has got everything to get you going.
It brings best features of Angular and React together
www.tothenew.com
Useful links
https://www.getrevue.co/profile/vuenewsletter
https://twitter.com/vuejs
https://stackoverflow.com/tags/vue.js/info
https://gitter.im/vuejs/vue
https://github.com/vuejs/awesome-vue
https://curated.vuejs.org/
https://frontendmasters.com/workshops/vue-advanced-features/
https://scotch.io/courses/build-an-online-shop-with-vue/introduction

More Related Content

What's hot (20)

PDF
An introduction to Vue.js
Javier Lafora Rey
 
KEY
HTML5 Web Messaging
Mike Taylor
 
PPTX
Effective C++/WinRT for UWP and Win32
Windows Developer
 
PPTX
Building Progressive Web Apps for Windows devices
Windows Developer
 
ODP
AngularJs Crash Course
Keith Bloomfield
 
PDF
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
PDF
Basic Tutorial of React for Programmers
David Rodenas
 
PDF
Create a meteor chat app in 30 minutes
Designveloper
 
PPT
Advanced Silverlight
Jeff Blankenburg
 
PDF
The Point of Vue - Intro to Vue.js
Holly Schinsky
 
PDF
How to build twitter bot using golang from scratch
Katy Slemon
 
PPT
Web Performance Tips
Ravi Raj
 
PDF
Maintainable JavaScript 2011
Nicholas Zakas
 
PDF
Boost your angular app with web workers
Enrique Oriol Bermúdez
 
PPTX
Backbone/Marionette recap [2015]
Andrii Lundiak
 
KEY
jQuery Bay Area Conference 2010
mennovanslooten
 
PPTX
The Screenplay Pattern: Better Interactions for Better Automation
Applitools
 
PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
An introduction to Vue.js
Javier Lafora Rey
 
HTML5 Web Messaging
Mike Taylor
 
Effective C++/WinRT for UWP and Win32
Windows Developer
 
Building Progressive Web Apps for Windows devices
Windows Developer
 
AngularJs Crash Course
Keith Bloomfield
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
Basic Tutorial of React for Programmers
David Rodenas
 
Create a meteor chat app in 30 minutes
Designveloper
 
Advanced Silverlight
Jeff Blankenburg
 
The Point of Vue - Intro to Vue.js
Holly Schinsky
 
How to build twitter bot using golang from scratch
Katy Slemon
 
Web Performance Tips
Ravi Raj
 
Maintainable JavaScript 2011
Nicholas Zakas
 
Boost your angular app with web workers
Enrique Oriol Bermúdez
 
Backbone/Marionette recap [2015]
Andrii Lundiak
 
jQuery Bay Area Conference 2010
mennovanslooten
 
The Screenplay Pattern: Better Interactions for Better Automation
Applitools
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 

Similar to An introduction to Vue.js (20)

PDF
How to Build ToDo App with Vue 3 + TypeScript
Katy Slemon
 
PDF
Love at first Vue
Dalibor Gogic
 
PDF
Introduction to VueJS & Vuex
Bernd Alter
 
PDF
Meet VueJs
Mathieu Breton
 
PDF
Vue.js part1
욱래 김
 
PDF
Vue fundamentasl with Testing and Vuex
Christoffer Noring
 
PDF
Introduction to Vue.js
Meir Rotstein
 
PDF
Knockoutjs databinding
Boulos Dib
 
PDF
Angular JS2 Training Session #2
Paras Mendiratta
 
PDF
Workshop: Building Vaadin add-ons
Sami Ekblad
 
PPTX
React render props
Saikat Samanta
 
PPTX
Membangun Moderen UI dengan Vue.js
Froyo Framework
 
PDF
How to build crud application using vue js, graphql, and hasura
Katy Slemon
 
PDF
NestJS
Wilson Su
 
PPT
Vanjs backbone-powerpoint
Michael Yagudaev
 
PDF
Vue.js for beginners
Julio Bitencourt
 
PPTX
Knockout.js
Vivek Rajan
 
PDF
Building and deploying React applications
Astrails
 
PPTX
Learning Svelte
Christoffer Noring
 
PPTX
How to Build SPA with Vue Router 2.0
Takuya Tejima
 
How to Build ToDo App with Vue 3 + TypeScript
Katy Slemon
 
Love at first Vue
Dalibor Gogic
 
Introduction to VueJS & Vuex
Bernd Alter
 
Meet VueJs
Mathieu Breton
 
Vue.js part1
욱래 김
 
Vue fundamentasl with Testing and Vuex
Christoffer Noring
 
Introduction to Vue.js
Meir Rotstein
 
Knockoutjs databinding
Boulos Dib
 
Angular JS2 Training Session #2
Paras Mendiratta
 
Workshop: Building Vaadin add-ons
Sami Ekblad
 
React render props
Saikat Samanta
 
Membangun Moderen UI dengan Vue.js
Froyo Framework
 
How to build crud application using vue js, graphql, and hasura
Katy Slemon
 
NestJS
Wilson Su
 
Vanjs backbone-powerpoint
Michael Yagudaev
 
Vue.js for beginners
Julio Bitencourt
 
Knockout.js
Vivek Rajan
 
Building and deploying React applications
Astrails
 
Learning Svelte
Christoffer Noring
 
How to Build SPA with Vue Router 2.0
Takuya Tejima
 
Ad

Recently uploaded (20)

PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Ad

An introduction to Vue.js