(Go: >> BACK << -|- >> HOME <<)

SlideShare a Scribd company logo
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

Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting Started
Murat Doğan
 
State manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to VuexState manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to Vuex
Commit University
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
Pagepro
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
Rafael Casuso Romate
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
Javier Lafora Rey
 
Vuex
VuexVuex
Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
Samundra khatri
 
Reactjs
ReactjsReactjs
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
Naphachara Rattanawilai
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
Holly Schinsky
 
Vue Vuex 101
Vue Vuex 101Vue Vuex 101
Vue Vuex 101
LocNguyen362
 
NestJS
NestJSNestJS
NestJS
Wilson Su
 
Basics of Vue.js 2019
Basics of Vue.js 2019Basics of Vue.js 2019
Basics of Vue.js 2019
Paul Bele
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch API
Xcat Liu
 
React hooks
React hooksReact hooks
React hooks
Assaf Gannon
 
.Net Core
.Net Core.Net Core
.Net Core
Bertrand Le Roy
 

What's hot (20)

Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting Started
 
State manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to VuexState manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to Vuex
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Vuex
VuexVuex
Vuex
 
Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
 
Reactjs
ReactjsReactjs
Reactjs
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
 
Vue Vuex 101
Vue Vuex 101Vue Vuex 101
Vue Vuex 101
 
NestJS
NestJSNestJS
NestJS
 
Basics of Vue.js 2019
Basics of Vue.js 2019Basics of Vue.js 2019
Basics of Vue.js 2019
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch API
 
React hooks
React hooksReact hooks
React hooks
 
.Net Core
.Net Core.Net Core
.Net Core
 

Similar to Introduction to VueJS & Vuex

An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
TO THE NEW Pvt. Ltd.
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
Astrails
 
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
Riad Benguella
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
Dalibor Gogic
 
Vue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and VuexVue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and Vuex
Christoffer Noring
 
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?
Tomasz Bak
 
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
Javier Abadía
 
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
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
Paras Mendiratta
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
Sergei Iastrebov
 
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
Krzysztof Bialek
 
Backbone js
Backbone jsBackbone js
Backbone js
Rohan Chandane
 
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
Takuya Tejima
 
Aurelia Meetup Paris
Aurelia Meetup ParisAurelia Meetup Paris
Aurelia Meetup Paris
Ahmed Radjdi
 
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
Rob Tweed
 
Vue business first
Vue business firstVue business first
Vue business first
Vitalii Ratyshnyi
 
2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
양재동 코드랩
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] 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
Simon Gauvin
 

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
 
2016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES62016 W3C Conference #4 : ANGULAR + ES6
2016 W3C Conference #4 : ANGULAR + ES6
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] 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

ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...
ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...
ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...
Ortus Solutions, Corp
 
Mumbai @Call @Girls Whatsapp 9930687706 With High Profile Service
Mumbai @Call @Girls Whatsapp 9930687706 With High Profile ServiceMumbai @Call @Girls Whatsapp 9930687706 With High Profile Service
Mumbai @Call @Girls Whatsapp 9930687706 With High Profile Service
kolkata dolls
 
Schrodinger’s Backup: Is Your Backup Really a Backup?
Schrodinger’s Backup: Is Your Backup Really a Backup?Schrodinger’s Backup: Is Your Backup Really a Backup?
Schrodinger’s Backup: Is Your Backup Really a Backup?
Ortus Solutions, Corp
 
NYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdfNYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdf
AUGNYC
 
mobile-app-development-company-in-noida.pdf
mobile-app-development-company-in-noida.pdfmobile-app-development-company-in-noida.pdf
mobile-app-development-company-in-noida.pdf
Mobile App Development Company in Noida - Drona Infotech
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
@Call @Girls in Ahmedabad 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Best High Class Ahmedabad Ava...
 @Call @Girls in Ahmedabad 🐱‍🐉  XXXXXXXXXX 🐱‍🐉  Best High Class Ahmedabad Ava... @Call @Girls in Ahmedabad 🐱‍🐉  XXXXXXXXXX 🐱‍🐉  Best High Class Ahmedabad Ava...
@Call @Girls in Ahmedabad 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Best High Class Ahmedabad Ava...
DiyaSharma6551
 
Kolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Kolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model SafeKolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Kolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Misti Soneji
 
Web Hosting with CommandBox and CommandBox Pro
Web Hosting with CommandBox and CommandBox ProWeb Hosting with CommandBox and CommandBox Pro
Web Hosting with CommandBox and CommandBox Pro
Ortus Solutions, Corp
 
Disk to Cloud: Abstract your File Operations with CBFS
Disk to Cloud: Abstract your File Operations with CBFSDisk to Cloud: Abstract your File Operations with CBFS
Disk to Cloud: Abstract your File Operations with CBFS
Ortus Solutions, Corp
 
@ℂall @Girls Kolkata ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
@ℂall @Girls Kolkata  ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe@ℂall @Girls Kolkata  ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
@ℂall @Girls Kolkata ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Misti Soneji
 
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
Hironori Washizaki
 
ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf
sachin chaurasia
 
Revolutionizing Task Scheduling in ColdBox
Revolutionizing Task Scheduling in ColdBoxRevolutionizing Task Scheduling in ColdBox
Revolutionizing Task Scheduling in ColdBox
Ortus Solutions, Corp
 
Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1
Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1
Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1
arvindkumarji156
 
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdfdachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
DNUG e.V.
 
@Call @Girls in Saharanpur 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas...
 @Call @Girls in Saharanpur 🐱‍🐉  XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas... @Call @Girls in Saharanpur 🐱‍🐉  XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas...
@Call @Girls in Saharanpur 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas...
AlinaDevecerski
 
@Call @Girls in Solapur 🤷‍♂️ XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S...
 @Call @Girls in Solapur 🤷‍♂️  XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S... @Call @Girls in Solapur 🤷‍♂️  XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S...
@Call @Girls in Solapur 🤷‍♂️ XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S...
Mona Rathore
 
Securing Your Application with Passkeys and cbSecurity
Securing Your Application with Passkeys and cbSecuritySecuring Your Application with Passkeys and cbSecurity
Securing Your Application with Passkeys and cbSecurity
Ortus Solutions, Corp
 
What is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for FreeWhat is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for Free
TwisterTools
 

Recently uploaded (20)

ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...
ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...
ColdBox Debugger v4.2.0: Unveiling Advanced Debugging Techniques for ColdBox ...
 
Mumbai @Call @Girls Whatsapp 9930687706 With High Profile Service
Mumbai @Call @Girls Whatsapp 9930687706 With High Profile ServiceMumbai @Call @Girls Whatsapp 9930687706 With High Profile Service
Mumbai @Call @Girls Whatsapp 9930687706 With High Profile Service
 
Schrodinger’s Backup: Is Your Backup Really a Backup?
Schrodinger’s Backup: Is Your Backup Really a Backup?Schrodinger’s Backup: Is Your Backup Really a Backup?
Schrodinger’s Backup: Is Your Backup Really a Backup?
 
NYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdfNYC 26-Jun-2024 Combined Presentations.pdf
NYC 26-Jun-2024 Combined Presentations.pdf
 
mobile-app-development-company-in-noida.pdf
mobile-app-development-company-in-noida.pdfmobile-app-development-company-in-noida.pdf
mobile-app-development-company-in-noida.pdf
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
@Call @Girls in Ahmedabad 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Best High Class Ahmedabad Ava...
 @Call @Girls in Ahmedabad 🐱‍🐉  XXXXXXXXXX 🐱‍🐉  Best High Class Ahmedabad Ava... @Call @Girls in Ahmedabad 🐱‍🐉  XXXXXXXXXX 🐱‍🐉  Best High Class Ahmedabad Ava...
@Call @Girls in Ahmedabad 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Best High Class Ahmedabad Ava...
 
Kolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Kolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model SafeKolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
Kolkata @ℂall @Girls ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
 
Web Hosting with CommandBox and CommandBox Pro
Web Hosting with CommandBox and CommandBox ProWeb Hosting with CommandBox and CommandBox Pro
Web Hosting with CommandBox and CommandBox Pro
 
Disk to Cloud: Abstract your File Operations with CBFS
Disk to Cloud: Abstract your File Operations with CBFSDisk to Cloud: Abstract your File Operations with CBFS
Disk to Cloud: Abstract your File Operations with CBFS
 
@ℂall @Girls Kolkata ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
@ℂall @Girls Kolkata  ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe@ℂall @Girls Kolkata  ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
@ℂall @Girls Kolkata ꧁❤ 000000000 ❤꧂@ℂall @Girls Service Vip Top Model Safe
 
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
 
ANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdfANSYS Mechanical APDL Introductory Tutorials.pdf
ANSYS Mechanical APDL Introductory Tutorials.pdf
 
Revolutionizing Task Scheduling in ColdBox
Revolutionizing Task Scheduling in ColdBoxRevolutionizing Task Scheduling in ColdBox
Revolutionizing Task Scheduling in ColdBox
 
Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1
Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1
Bhiwandi @Call @Girls Whatsapp 000000000 With Best And No 1
 
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdfdachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
 
@Call @Girls in Saharanpur 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas...
 @Call @Girls in Saharanpur 🐱‍🐉  XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas... @Call @Girls in Saharanpur 🐱‍🐉  XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas...
@Call @Girls in Saharanpur 🐱‍🐉 XXXXXXXXXX 🐱‍🐉 Tanisha Sharma Best High Clas...
 
@Call @Girls in Solapur 🤷‍♂️ XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S...
 @Call @Girls in Solapur 🤷‍♂️  XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S... @Call @Girls in Solapur 🤷‍♂️  XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S...
@Call @Girls in Solapur 🤷‍♂️ XXXXXXXX 🤷‍♂️ Tanisha Sharma Best High Class S...
 
Securing Your Application with Passkeys and cbSecurity
Securing Your Application with Passkeys and cbSecuritySecuring Your Application with Passkeys and cbSecurity
Securing Your Application with Passkeys and cbSecurity
 
What is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for FreeWhat is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for Free
 

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