Building a Single Page
Application (SPA) with
VueJS
@danpastori
Hi 👋
Hi 👋
I’m Dan Pastori
I’m From Wisconsin
I’m passionate about traveling ✈
Drinking coffee ☕
I’m passionate about traveling ✈
Drinking coffee ☕
I’m passionate about traveling ✈
Being in nature 🍁
Drinking coffee ☕
I’m passionate about traveling ✈
Being in nature 🍁
And of course…
Drinking coffee ☕
I’m passionate about traveling ✈
Being in nature 🍁
And of course…
Everything to do with
making apps!!!
I’ve been developing for 12 years
I’ve been developing for 12 years
8 years ago, Jay Rogers and I started
521 Dimensions
https://521dimensions.com
@521dimensions
We build 100% custom web and
mobile applications and specialize in API
Driven Development (SPA + API)
For our applications, we use a variety of
tools and languages….
For our applications, we use a variety of
tools and languages….
But our preferred front end framework is
VueJS!
Before we dive in, I wanted
to make 2 points:
Before we dive in, I wanted
to make 2 points:
1. This will be an open talk!
Meaning I’ll share my
experiences, show tutorials,
and discuss the wonders of
VueJS
But…. It’s also a time for you
all to pipe up with questions,
concerns, comments
whatever you think is
beneficial to the group and
understanding!
Before we dive in, I wanted
to make 2 points:
2. Like all developers, I have
an opinion
That doesn’t mean I’m right
and anyone using Angular,
React, Stimulus, etc. is
wrong..
I just ❤ Vue and my goal is
show you how awesome it is
even as an alternative.. And
that SPAs are awesome too!
Which is probably
controversial.. but we will get
there 🥰
First off, how many of you
have used Vue? ✋
How many have built an
SPA? 🛁
How many of you have used
ReactJS, AngularJS, or
something similar? ✋
Let’s do a quick comparison
between Vue + React & Vue +
Angular
Let’s do a quick comparison
between Vue + React & Vue +
Angular
I’ll do my best being out of the ReactJS and Angular
communities for some time
https://vuejs.org/v2/guide/comparison.html
VueJS vs Angular 🥊
Angular is Backed by Google
Angular is Backed by Google
(VueJS creator Evan You worked on Angular when he was
at Google)
Angular is built heavily on TypeScript, VueJS it’s
optional
https://buttercms.com/blog/comparing-angular-vs-vue
Angular is Backed by Google
(VueJS creator Evan You worked on Angular when he was
at Google)
https://buttercms.com/blog/comparing-angular-vs-vue
Angular is Backed by Google
(VueJS creator Evan You worked on Angular when he was
at Google)
Angular is built heavily on TypeScript, VueJS it’s
optional
Angular has a much more opinionated
architecture where VueJS is flexible
Angular is Backed by Google
(VueJS creator Evan You worked on Angular when he was
at Google)
Angular has a much larger footprint (500+ KB vs
80KB)
https://www.themexpert.com/blog/angular-vs-react-vs-vue
Angular is built heavily on TypeScript, VueJS it’s
optional
Angular has a much more opinionated
architecture where VueJS is flexible
Angular is Backed by Google
(VueJS creator Evan You worked on Angular when he was
at Google)
Angular has a much larger footprint (500+ KB vs
80KB)
https://www.themexpert.com/blog/angular-vs-react-vs-vue
Angular is built heavily on TypeScript, VueJS it’s
optional
Angular has a much more opinionated
architecture where VueJS is flexible
Angular is MVVM (Model-View-ViewModel)
VueJS vs React 🥊
React is Backed by Facebook
React is Backed by Facebook
React uses JSX. Vue allows you to use Web
Components ❤ or JSX
QUICK TANGENT! 🚨
Web Components are AAAAHHHMAZING!!
<template>
<router-link :to="route" class="no-underline">
<div class="mt-2 mb-2 left-nav-link text-center h-16 flex flex-col items-center justify-center
cursor-pointer"
v-bind:class="{ 'bg-blue-500 border-l-2 border-white border-solid' : currentRoute ==
route }">
<slot name="image"></slot>
<span class="text-xs mt-2 block text-center"
v-bind:class="{
'text-gray-400': currentRoute != route,
'text-white' : currentRoute == route
}">
<slot name="name"></slot>
</span>
</div>
</router-link>
</template>
<script>
export default {
props: ['route'],
data(){
return {
currentRoute: this.$router.currentRoute.name
}
},
}
</script>
React is Backed by Facebook
React uses JSX. Vue allows you to use Web
Components ❤ or JSX
Official packages (state management and router)
for React are 3rd Party
https://buttercms.com/blog/comparing-angular-vs-vue
React is Backed by Facebook
React uses JSX. Vue allows you to use Web
Components ❤ or JSX
Official packages (state management and router)
for React are 3rd Party
https://buttercms.com/blog/comparing-angular-vs-vue
React has React Native. VueJS has ports like
NativeScript
So why I love Vue!
So why I love Vue!
1. The documentation is incredible
So why I love Vue!
1. The documentation is incredible
* Third party docs are amazing as well!
So why I love Vue!
2. Ability to use Web Components
So why I love Vue!
2. Ability to use Web Components
All Javscript, Template HTML, and
CSS are in one re-usable file
So why I love Vue!
2. Ability to use Web Components
All Javscript, Template HTML, and
CSS are in one re-usable file
With slots, it’s even more reusable!
So why I love Vue!
3. State Management and Router are
NOT 3rd Party!
So why I love Vue!
3. State Management and Router are
NOT 3rd Party!
That’s right! Vue-Router and Vuex are
official.
So why I love Vue!
4. Not maintained by a large
corporation
So why I love Vue!
4. Not maintained by a large
corporation
This may sound weird, but I love how
Vue is run and managed.
So why I love Vue!
5. Excellent tools
So why I love Vue!
5. Excellent tools
•Chrome Debugger
•Server Side Rendering
•Vue CLI
https://insights.stackoverflow.com/survey/2019#most-loved-
dreaded-and-wanted
Other Devs Love Vue Too!
Let’s talk a little bit about the
core modules of VueJS!
First, we have the core library
https://vuejs.org
This is where all of the core
features are packed such as:
• Reactivity
• Housing of local data
• Template Rendering
• Registering of Components
You also get features like:
• Mixins
• Transitions
• Form Input Bindings
• Computed Properties
Don’t worry, we will see all of
this in action! 🔥
Next, we have the vue-router
library
https://router.vuejs.org/
Vue Router takes care of
• HTML 5 History API Management
• Navigating without full page reloading
• Nested Routing
With Vue Router you also get
features like:
• Named Routes
• Route Meta Data
• Redirecting
• Hooks that can be used for guarding and
authorization.
Essentially, Vue-Router is
what makes Single Page
Applications Possible!
🏄
Last but not least, we have the
Vuex library
https://vuex.vuejs.org/
Vuex is Vue’s version of Redux
for React. It’s a “state
management pattern +
library” inspired by Redux and
Flux
For the React Devs in the
room, you may recognize Dan
Abramov’s quote.
“Flux libraries are like glasses: you’ll know when you
need them.”
For the React Devs in the
room, you may recognize Dan
Abramov’s quote.
“Flux libraries are like glasses: you’ll know when you
need them.”
That’s by far the best definition of when you should use a flux library.
Vuex handles the state for
your large scale SPAs.
State is made up of modules
which in turn have:
• Localized State
• Getters
• Mutations
• Actions
https://vuex.vuejs.org/
The way I look at it. If you keep passing
properties and you need the same data
on your page more than 5 times, might
be time to look at Vuex.
Let’s mix it all together and
make some VueJS Magic!
-
Real quick, has anyone built an
SPA?
Let’s spend 1 minute defining what an
SPA is.
A Single Page Application Means:
•The page doesn’t make a full refresh when
navigating
A Single Page Application Means:
•The page doesn’t make a full refresh when
navigating
•We rely on the HTML 5 History API for navigation
A Single Page Application Means:
•The page doesn’t make a full refresh when
navigating
•We rely on the HTML 5 History API for navigation
•Usually communicates to some sort of API to
retrieve data
A Single Page Application Means:
•The page doesn’t make a full refresh when
navigating
•We rely on the HTML 5 History API for navigation
•Usually communicates to some sort of API to
retrieve data
•You make an initial load of assets and then load
the rest on demand
What we are building
•Simple Contact Book
•We will have 3 Routes
•Contacts
•Contact
•Add Contact
•We will have Vuex for state, vue-router for nav
and Vue for display.
📒
Let’s begin!!
So I did a little set up… Just to save
time ⏱
1. I set up a quick project using the Vue
CLI (Yup, they have that too). Which
installed Vue, Vuex, and Vue Router.
2. Next I installed Axios.js for HTTP
requests.
https://github.com/axios/axios
3. I added two directories:
• ./src/api
•./src/state
4. I added the contacts module and
imported it into the store.
5. I added the contacts API and
imported it into the contacts module.
This allows us to keep our API routes
separate and easy to edit.
6. I also set up a simple PHP API we
will hit. It has the following routes:
• GET /api/v1/contacts
• GET /api/v1/contacts/{id}
• POST /api/v1/contacts
• PUT /api/v1/contacts/{id}
This does not have authentication, you
will see the route in this presentation. It
will be accessible on the network.
Please be nice ☺
Time to switch to VS Code!!
Vue Life Cycle Diagram
https://vuejs.org/v2/guide/instance.html#Lifecycle-Diagram
https://vuex.vuejs.org/
Vuex Flow
Any Feedback, Questions, Etc?
Thank you!
If you need any help you can find me at:
@danpastori
https://serversideup.net
https://github.com/521dimensions

Building a Single Page Application with VueJS

  • 1.
    Building a SinglePage Application (SPA) with VueJS @danpastori
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
    Drinking coffee ☕ I’mpassionate about traveling ✈
  • 7.
    Drinking coffee ☕ I’mpassionate about traveling ✈ Being in nature 🍁
  • 8.
    Drinking coffee ☕ I’mpassionate about traveling ✈ Being in nature 🍁 And of course…
  • 9.
    Drinking coffee ☕ I’mpassionate about traveling ✈ Being in nature 🍁 And of course… Everything to do with making apps!!!
  • 10.
  • 11.
    I’ve been developingfor 12 years 8 years ago, Jay Rogers and I started 521 Dimensions https://521dimensions.com @521dimensions
  • 12.
    We build 100%custom web and mobile applications and specialize in API Driven Development (SPA + API)
  • 13.
    For our applications,we use a variety of tools and languages….
  • 14.
    For our applications,we use a variety of tools and languages…. But our preferred front end framework is VueJS!
  • 15.
    Before we divein, I wanted to make 2 points:
  • 16.
    Before we divein, I wanted to make 2 points: 1. This will be an open talk!
  • 17.
    Meaning I’ll sharemy experiences, show tutorials, and discuss the wonders of VueJS
  • 18.
    But…. It’s alsoa time for you all to pipe up with questions, concerns, comments whatever you think is beneficial to the group and understanding!
  • 19.
    Before we divein, I wanted to make 2 points: 2. Like all developers, I have an opinion
  • 20.
    That doesn’t meanI’m right and anyone using Angular, React, Stimulus, etc. is wrong..
  • 21.
    I just ❤Vue and my goal is show you how awesome it is even as an alternative.. And that SPAs are awesome too!
  • 22.
    Which is probably controversial..but we will get there 🥰
  • 23.
    First off, howmany of you have used Vue? ✋
  • 24.
    How many havebuilt an SPA? 🛁
  • 25.
    How many ofyou have used ReactJS, AngularJS, or something similar? ✋
  • 26.
    Let’s do aquick comparison between Vue + React & Vue + Angular
  • 27.
    Let’s do aquick comparison between Vue + React & Vue + Angular I’ll do my best being out of the ReactJS and Angular communities for some time https://vuejs.org/v2/guide/comparison.html
  • 28.
  • 29.
  • 30.
    Angular is Backedby Google (VueJS creator Evan You worked on Angular when he was at Google)
  • 31.
    Angular is builtheavily on TypeScript, VueJS it’s optional https://buttercms.com/blog/comparing-angular-vs-vue Angular is Backed by Google (VueJS creator Evan You worked on Angular when he was at Google)
  • 32.
    https://buttercms.com/blog/comparing-angular-vs-vue Angular is Backedby Google (VueJS creator Evan You worked on Angular when he was at Google) Angular is built heavily on TypeScript, VueJS it’s optional Angular has a much more opinionated architecture where VueJS is flexible
  • 33.
    Angular is Backedby Google (VueJS creator Evan You worked on Angular when he was at Google) Angular has a much larger footprint (500+ KB vs 80KB) https://www.themexpert.com/blog/angular-vs-react-vs-vue Angular is built heavily on TypeScript, VueJS it’s optional Angular has a much more opinionated architecture where VueJS is flexible
  • 34.
    Angular is Backedby Google (VueJS creator Evan You worked on Angular when he was at Google) Angular has a much larger footprint (500+ KB vs 80KB) https://www.themexpert.com/blog/angular-vs-react-vs-vue Angular is built heavily on TypeScript, VueJS it’s optional Angular has a much more opinionated architecture where VueJS is flexible Angular is MVVM (Model-View-ViewModel)
  • 35.
  • 36.
    React is Backedby Facebook
  • 37.
    React is Backedby Facebook React uses JSX. Vue allows you to use Web Components ❤ or JSX
  • 38.
  • 39.
    Web Components areAAAAHHHMAZING!! <template> <router-link :to="route" class="no-underline"> <div class="mt-2 mb-2 left-nav-link text-center h-16 flex flex-col items-center justify-center cursor-pointer" v-bind:class="{ 'bg-blue-500 border-l-2 border-white border-solid' : currentRoute == route }"> <slot name="image"></slot> <span class="text-xs mt-2 block text-center" v-bind:class="{ 'text-gray-400': currentRoute != route, 'text-white' : currentRoute == route }"> <slot name="name"></slot> </span> </div> </router-link> </template> <script> export default { props: ['route'], data(){ return { currentRoute: this.$router.currentRoute.name } }, } </script>
  • 40.
    React is Backedby Facebook React uses JSX. Vue allows you to use Web Components ❤ or JSX Official packages (state management and router) for React are 3rd Party https://buttercms.com/blog/comparing-angular-vs-vue
  • 41.
    React is Backedby Facebook React uses JSX. Vue allows you to use Web Components ❤ or JSX Official packages (state management and router) for React are 3rd Party https://buttercms.com/blog/comparing-angular-vs-vue React has React Native. VueJS has ports like NativeScript
  • 42.
    So why Ilove Vue!
  • 43.
    So why Ilove Vue! 1. The documentation is incredible
  • 44.
    So why Ilove Vue! 1. The documentation is incredible * Third party docs are amazing as well!
  • 45.
    So why Ilove Vue! 2. Ability to use Web Components
  • 46.
    So why Ilove Vue! 2. Ability to use Web Components All Javscript, Template HTML, and CSS are in one re-usable file
  • 47.
    So why Ilove Vue! 2. Ability to use Web Components All Javscript, Template HTML, and CSS are in one re-usable file With slots, it’s even more reusable!
  • 48.
    So why Ilove Vue! 3. State Management and Router are NOT 3rd Party!
  • 49.
    So why Ilove Vue! 3. State Management and Router are NOT 3rd Party! That’s right! Vue-Router and Vuex are official.
  • 50.
    So why Ilove Vue! 4. Not maintained by a large corporation
  • 51.
    So why Ilove Vue! 4. Not maintained by a large corporation This may sound weird, but I love how Vue is run and managed.
  • 52.
    So why Ilove Vue! 5. Excellent tools
  • 53.
    So why Ilove Vue! 5. Excellent tools •Chrome Debugger •Server Side Rendering •Vue CLI
  • 54.
  • 55.
    Let’s talk alittle bit about the core modules of VueJS!
  • 56.
    First, we havethe core library https://vuejs.org
  • 57.
    This is whereall of the core features are packed such as: • Reactivity • Housing of local data • Template Rendering • Registering of Components
  • 58.
    You also getfeatures like: • Mixins • Transitions • Form Input Bindings • Computed Properties
  • 59.
    Don’t worry, wewill see all of this in action! 🔥
  • 60.
    Next, we havethe vue-router library https://router.vuejs.org/
  • 61.
    Vue Router takescare of • HTML 5 History API Management • Navigating without full page reloading • Nested Routing
  • 62.
    With Vue Routeryou also get features like: • Named Routes • Route Meta Data • Redirecting • Hooks that can be used for guarding and authorization.
  • 63.
    Essentially, Vue-Router is whatmakes Single Page Applications Possible! 🏄
  • 64.
    Last but notleast, we have the Vuex library https://vuex.vuejs.org/
  • 65.
    Vuex is Vue’sversion of Redux for React. It’s a “state management pattern + library” inspired by Redux and Flux
  • 66.
    For the ReactDevs in the room, you may recognize Dan Abramov’s quote. “Flux libraries are like glasses: you’ll know when you need them.”
  • 67.
    For the ReactDevs in the room, you may recognize Dan Abramov’s quote. “Flux libraries are like glasses: you’ll know when you need them.” That’s by far the best definition of when you should use a flux library.
  • 68.
    Vuex handles thestate for your large scale SPAs. State is made up of modules which in turn have: • Localized State • Getters • Mutations • Actions
  • 69.
  • 70.
    The way Ilook at it. If you keep passing properties and you need the same data on your page more than 5 times, might be time to look at Vuex.
  • 71.
    Let’s mix itall together and make some VueJS Magic! -
  • 72.
    Real quick, hasanyone built an SPA?
  • 73.
    Let’s spend 1minute defining what an SPA is.
  • 74.
    A Single PageApplication Means: •The page doesn’t make a full refresh when navigating
  • 75.
    A Single PageApplication Means: •The page doesn’t make a full refresh when navigating •We rely on the HTML 5 History API for navigation
  • 76.
    A Single PageApplication Means: •The page doesn’t make a full refresh when navigating •We rely on the HTML 5 History API for navigation •Usually communicates to some sort of API to retrieve data
  • 77.
    A Single PageApplication Means: •The page doesn’t make a full refresh when navigating •We rely on the HTML 5 History API for navigation •Usually communicates to some sort of API to retrieve data •You make an initial load of assets and then load the rest on demand
  • 78.
    What we arebuilding •Simple Contact Book •We will have 3 Routes •Contacts •Contact •Add Contact •We will have Vuex for state, vue-router for nav and Vue for display. 📒
  • 79.
  • 80.
    So I dida little set up… Just to save time ⏱
  • 81.
    1. I setup a quick project using the Vue CLI (Yup, they have that too). Which installed Vue, Vuex, and Vue Router.
  • 82.
    2. Next Iinstalled Axios.js for HTTP requests. https://github.com/axios/axios
  • 83.
    3. I addedtwo directories: • ./src/api •./src/state
  • 84.
    4. I addedthe contacts module and imported it into the store.
  • 85.
    5. I addedthe contacts API and imported it into the contacts module. This allows us to keep our API routes separate and easy to edit.
  • 86.
    6. I alsoset up a simple PHP API we will hit. It has the following routes: • GET /api/v1/contacts • GET /api/v1/contacts/{id} • POST /api/v1/contacts • PUT /api/v1/contacts/{id}
  • 87.
    This does nothave authentication, you will see the route in this presentation. It will be accessible on the network. Please be nice ☺
  • 88.
    Time to switchto VS Code!!
  • 89.
    Vue Life CycleDiagram https://vuejs.org/v2/guide/instance.html#Lifecycle-Diagram
  • 90.
  • 91.
  • 92.
  • 93.
    If you needany help you can find me at: @danpastori https://serversideup.net https://github.com/521dimensions