SlideShare a Scribd company logo
1 of 26
Download to read offline
Introduction to VueJS & Vuex
About me
Bernd Alter
Technical Director at Turbine Kreuzberg
Tech lead, father, boardgame enthusiast, DJ
bernd.alter@turbinekreuzberg.com
@bazoo0815
Agenda
Basics
Bindings
Conditionals & lists
Slots
Routing
Components
State management with Vuex
Tipps & tricks
Basics
Use npm package vue-cli
Easy scaffolding
vue init <template-name> <project-name>
vue init webpack my-vue-app
Basics
Vue instance (single/multiple)
Mustache template syntax
Lifecycle hooks: created, mounted, updated, destroyed
<span>Message: {{ msg }}</span>
<script>
var vm = new Vue({
data () {
return {
msg: 'my message'
}
},
mounted () {
this.$emit('mounted');
}
// more code
})
</script>
Bindings
Attributes: v-bind (shorthand :)
Example:
Result:
<div class="static"
v-bind:class="{ active: isActive, 'danger': hasError }"
:text="dynamicText">
</div>
<script>
data: {
isActive: true,
hasError: false,
dynamicText: 'my dynamic text'
}
</script>
<div class="static active">my dynamic text</div>
Bindings
Events: v-on (shorthand @)
<button v-on:click="onClick">click me</button>
<button @click="onClick">click me</button>
<script>
methods: {
onClick () { // do something on clicking the button }
}
</script>
Bindings
Events: v-on - Modifiers
Key modi ers
use key codes
or more convenient: built-in modi ers
.enter, .tab, .esc, .space, .up, .down, .left, .right, .delete (both 'delete' and
'backspace')
<input v-on:keyup.13="onKeyEnter"></input>
# same as previous
<input @keyup.enter="onKeyEnter"></input>
Bindings
Events: v-on - Modifiers
Event modi ers
.prevent, .stop, .capture, .self, .once
System modi ers
v2.1.0+: .ctrl, .alt, .shift, .meta
v2.5.0+: .exact (single key only)
Mouse button modi ers
.left, .right, .middle
<a v-on:click.prevent="onClick"></a>
Conditionals
v-if, v-else, v-else-if
v-show
always rendered, toggled by CSS classes
v-show vs. v-if
v-if: higher toggle costs
v-show: higher initial render costs
<button v-if="isUserLoggedIn">Logout</button>
<button v-else>Login</button>
<div v-show="showInfo">Hidden info</div>
Lists/loops: v-for
possible for both HTML elements and Vue components
use key attribute for better binding
index or key can be used
<ul>
<li v-for="(user,index) in users" key="user.id">{{ index }} {{ user.name }}</li>
</ul>
<script>
data: {
users: [
{ id: 1, name: 'Bernd' },
{ id: 2, name: 'Stefan' }
]
}
</script>
Slots
like containers inside components
can have default content
name multiple slots
<template>
<div>
<h1>List</h1>
<slot>
Some default content
</slot>
</div>
</template>
<my-component>
<p>Lorem <strong>ipsum</strong> dolor sit amet</p>
</my-component>
<div>
<h1>List</h1>
<p>Lorem <strong>ipsum</strong> dolor sit amet</p>
</div>
Routing
Use component vue-router
<template>
<div id="app">
<router-link to="/demo">Demo</router-link>
<router-view/>
</div>
</template>
<script>
Vue.use(Router)
export default new Router({
routes: [
{
path: '/demo',
name: 'Demo',
component: Demo
}
]
})
</script>
Components
Wrapped in single les with ending .vue
### MyBoxComponent.vue
<template>
<div>
<h1><slot name="title">Default title</slot></h1>
<p><slot>Default content</slot></p>
</div>
</template>
<script>
export default {
data () {
return {
// component data
}
}
}
</script>
<style>
/* some css here */
</style>
Components
<script>
export default {
props: {
// data to pass into component on init
}
data () {
return {
// component data
}
},
methods: {
// component methods go here
},
computed: {
// computed properties with reactive binding
},
watch: {
// watcher functions (rather use computed properties)
}
}
</script>
Components
props
component properties
de ned with type (mandatory) & default value (optional)
props: {
label: {
type: String,
default: 'click me',
required: true
},
importantProp: {
type: Number,
required: true
},
callback: {
type: Function,
default: function() {}
}
}
Components
computed & methods
computed vs methods:
computed properties are cached as long as data does not change
computed: by default only getters, but also setters possible
computed: {
fullname () {
return this.firstname + ' ' + this.lastname; // cached
}
},
methods: {
fullname () {
return this.firstname + ' ' + this.lastname; // always executed
}
}
Components
watch
similar to computed
usually not necessary, rather use computed
Vuex
state management library/pattern
based on/inspired by Flux & Redux
organized in so-called store
store can be split into modules
Vuex
https://vuex.vuejs.org/en/intro.html
Vuex
state
immutable, changed only by mutations
mutations
only place to modify (=mutate) the store state
actions
methods calling mutations
for asynchronous calls
getters
methods to access state properties
use mapGetters in computed of components
add more custom computed properties by using ... (spread operator)
Tipps & tricks
use Chrome plugin Vue
DevTools
great inspections for
components & events
Vuex state management
(with time travel
functionality)
Tipps & tricks
use hot reloading with vue-loader
applies changes without page-reload
enabled by default
make sure to add watchOptions to dev-server.js
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
},
// add these lines if missing
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
})
Links
VueJS guide:
VueJS API:
VueJS video tutorials:
Awesome Vue (link collection):
Vue Devtools (Chrome plugin):
Vuex:
Vuex video tutorials:
https://vuejs.org/v2/guide/
https://vuejs.org/v2/api/
https://laracasts.com/series/learn-vue-2-step-by-
step
https://github.com/vuejs/awesome-vue
https://chrome.google.com/webstore/detail/vuejs-
devtools/nhdogjmejiglipccpnnnanhbledajbpd
https://vuex.vuejs.org/en/
https://www.youtube.com/playlist?
list=PL55RiY5tL51pT0DNJraU93FhMzhXxtDAo
Take aways
Use VueJS!
Split up your app into reusable components
Use Vuex for complex state handling
Stick with simple event (bus) handling for simple apps
Use Vue DevTools for dev/debugging
Thanks for listening
@bazoo0815
https://github.com/coding-berlin/vuejs-demo
https://de.slideshare.net/berndalter7

More Related Content

What's hot

What's hot (20)

An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Server side rendering review
Server side rendering reviewServer side rendering review
Server side rendering review
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Why Vue.js?
Why Vue.js?Why Vue.js?
Why Vue.js?
 
React JS
React JSReact JS
React JS
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
Vue JS Intro
Vue JS IntroVue JS Intro
Vue JS Intro
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 
Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting Started
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
React state
React  stateReact  state
React state
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
ReactJs
ReactJsReactJs
ReactJs
 
Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
 
Learning Svelte
Learning SvelteLearning Svelte
Learning Svelte
 

Similar to Introduction to VueJS & Vuex

09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 

Similar to Introduction to VueJS & Vuex (20)

An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
Gutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesGutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisables
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
Vue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and VuexVue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and Vuex
 
How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
 
Backbone js
Backbone jsBackbone js
Backbone js
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
 
Aurelia Meetup Paris
Aurelia Meetup ParisAurelia Meetup Paris
Aurelia Meetup Paris
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
 
Vue business first
Vue business firstVue business first
Vue business first
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6
 
2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
 
Angular 1 + es6
Angular 1 + es6Angular 1 + es6
Angular 1 + es6
 
Introduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinIntroduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon Gauvin
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Introduction to VueJS & Vuex

  • 2. About me Bernd Alter Technical Director at Turbine Kreuzberg Tech lead, father, boardgame enthusiast, DJ bernd.alter@turbinekreuzberg.com @bazoo0815
  • 4. Basics Use npm package vue-cli Easy scaffolding vue init <template-name> <project-name> vue init webpack my-vue-app
  • 5. Basics Vue instance (single/multiple) Mustache template syntax Lifecycle hooks: created, mounted, updated, destroyed <span>Message: {{ msg }}</span> <script> var vm = new Vue({ data () { return { msg: 'my message' } }, mounted () { this.$emit('mounted'); } // more code }) </script>
  • 6. Bindings Attributes: v-bind (shorthand :) Example: Result: <div class="static" v-bind:class="{ active: isActive, 'danger': hasError }" :text="dynamicText"> </div> <script> data: { isActive: true, hasError: false, dynamicText: 'my dynamic text' } </script> <div class="static active">my dynamic text</div>
  • 7. Bindings Events: v-on (shorthand @) <button v-on:click="onClick">click me</button> <button @click="onClick">click me</button> <script> methods: { onClick () { // do something on clicking the button } } </script>
  • 8. Bindings Events: v-on - Modifiers Key modi ers use key codes or more convenient: built-in modi ers .enter, .tab, .esc, .space, .up, .down, .left, .right, .delete (both 'delete' and 'backspace') <input v-on:keyup.13="onKeyEnter"></input> # same as previous <input @keyup.enter="onKeyEnter"></input>
  • 9. Bindings Events: v-on - Modifiers Event modi ers .prevent, .stop, .capture, .self, .once System modi ers v2.1.0+: .ctrl, .alt, .shift, .meta v2.5.0+: .exact (single key only) Mouse button modi ers .left, .right, .middle <a v-on:click.prevent="onClick"></a>
  • 10. Conditionals v-if, v-else, v-else-if v-show always rendered, toggled by CSS classes v-show vs. v-if v-if: higher toggle costs v-show: higher initial render costs <button v-if="isUserLoggedIn">Logout</button> <button v-else>Login</button> <div v-show="showInfo">Hidden info</div>
  • 11. Lists/loops: v-for possible for both HTML elements and Vue components use key attribute for better binding index or key can be used <ul> <li v-for="(user,index) in users" key="user.id">{{ index }} {{ user.name }}</li> </ul> <script> data: { users: [ { id: 1, name: 'Bernd' }, { id: 2, name: 'Stefan' } ] } </script>
  • 12. Slots like containers inside components can have default content name multiple slots <template> <div> <h1>List</h1> <slot> Some default content </slot> </div> </template> <my-component> <p>Lorem <strong>ipsum</strong> dolor sit amet</p> </my-component> <div> <h1>List</h1> <p>Lorem <strong>ipsum</strong> dolor sit amet</p> </div>
  • 13. Routing Use component vue-router <template> <div id="app"> <router-link to="/demo">Demo</router-link> <router-view/> </div> </template> <script> Vue.use(Router) export default new Router({ routes: [ { path: '/demo', name: 'Demo', component: Demo } ] }) </script>
  • 14. Components Wrapped in single les with ending .vue ### MyBoxComponent.vue <template> <div> <h1><slot name="title">Default title</slot></h1> <p><slot>Default content</slot></p> </div> </template> <script> export default { data () { return { // component data } } } </script> <style> /* some css here */ </style>
  • 15. Components <script> export default { props: { // data to pass into component on init } data () { return { // component data } }, methods: { // component methods go here }, computed: { // computed properties with reactive binding }, watch: { // watcher functions (rather use computed properties) } } </script>
  • 16. Components props component properties de ned with type (mandatory) & default value (optional) props: { label: { type: String, default: 'click me', required: true }, importantProp: { type: Number, required: true }, callback: { type: Function, default: function() {} } }
  • 17. Components computed & methods computed vs methods: computed properties are cached as long as data does not change computed: by default only getters, but also setters possible computed: { fullname () { return this.firstname + ' ' + this.lastname; // cached } }, methods: { fullname () { return this.firstname + ' ' + this.lastname; // always executed } }
  • 18. Components watch similar to computed usually not necessary, rather use computed
  • 19. Vuex state management library/pattern based on/inspired by Flux & Redux organized in so-called store store can be split into modules
  • 21. Vuex state immutable, changed only by mutations mutations only place to modify (=mutate) the store state actions methods calling mutations for asynchronous calls getters methods to access state properties use mapGetters in computed of components add more custom computed properties by using ... (spread operator)
  • 22. Tipps & tricks use Chrome plugin Vue DevTools great inspections for components & events Vuex state management (with time travel functionality)
  • 23. Tipps & tricks use hot reloading with vue-loader applies changes without page-reload enabled by default make sure to add watchOptions to dev-server.js var devMiddleware = require('webpack-dev-middleware')(compiler, { publicPath: webpackConfig.output.publicPath, stats: { colors: true, chunks: false }, // add these lines if missing watchOptions: { aggregateTimeout: 300, poll: 1000 } })
  • 24. Links VueJS guide: VueJS API: VueJS video tutorials: Awesome Vue (link collection): Vue Devtools (Chrome plugin): Vuex: Vuex video tutorials: https://vuejs.org/v2/guide/ https://vuejs.org/v2/api/ https://laracasts.com/series/learn-vue-2-step-by- step https://github.com/vuejs/awesome-vue https://chrome.google.com/webstore/detail/vuejs- devtools/nhdogjmejiglipccpnnnanhbledajbpd https://vuex.vuejs.org/en/ https://www.youtube.com/playlist? list=PL55RiY5tL51pT0DNJraU93FhMzhXxtDAo
  • 25. Take aways Use VueJS! Split up your app into reusable components Use Vuex for complex state handling Stick with simple event (bus) handling for simple apps Use Vue DevTools for dev/debugging