Vuex 4 & Firebase Auth Tutorial #3 - Vuex & the Composition API
Key Takeaways
This video tutorial demonstrates how to use Vuex 4 with the Composition API in Vue.js, specifically using the useStore function to access the store and its state and mutations. The tutorial shows how to replace the Options API with the Composition API, using the setup hook to define reactive values and methods.
Full Transcript
so then gang now we've seen the basics of how view x works how we can make a store add states and mutations and then access all of this from inside components and at the minute we do all of this using the options api which is the slightly older way of working with vue.js where we define methods and computed values like this as properties on our component object now i'd like to show you how to do this using the composition api instead which doesn't use these properties but instead uses a setup hook and then inside that setup hook we can place all of our reactive values and methods and then return the ones that we need to use in the template at the end of it now again at this point i'm assuming you already know a bit about working with vue this way using the composition api if not definitely check out my view three courses first of all because i talk about them extensively in those the links are going to be down below anyway the way we work with vuex using the composition api is by using a function new in view x version 4 called use store and this gives us access to the store and the state and mutations on that store so the first thing we need to do is import that function from the view x library and like i said this is brand new to view x4 so make sure you have that version installed for this to work so what i'd like to do then is basically keep all of the same functionality we're still going to get the points from the store and we're still going to commit this mutation right here but we're going to do it all inside the setup hook using this function right here use store now the reason we need this function ustor is because we need to use that function to get access to the store itself now before when we use the composition api down here we could say this dot store but we don't have access to this inside the setup function so we can't do that in here and that's why we use this instead because this function returns to us the store so i'm going to say down here const and i'll call it store and set it equal to use store like so and what that does is get us access to the store so now this is basically the same as this thing right here and we can use the same different properties and methods on it so i could grab the points i could say const points is equal to something now it's a computed property much like we used a computer property down here so we need to say computed and also we need to import that from view as well this is the way we work in the composition api we import the functions we need and then inside that computed function we basically just want to return a value and the value that we want to return is going to be the store which we have access to because of this right here dot state dot points so it's exactly the same as this down here the store.state.points only instead of using this dollar sign store we use this function to get the store and use the properties on this instead okay so now we can return the points down here so this now is doing exactly the same thing as this so now we can get rid of this computed property we don't need that anymore all right so next let's do this method so same again we just need to create a function so i'm going to call this update points again and we set it equal to a function we're going to take in the points p call it what you want i called it points down here but i'm calling it p up here so as not to get this p confused with the points we have right here so then inside the function all we need to do is say store dot commit and then whatever mutation we want to commit which is update points in our case and then pass in p as the second argument that's the payload all right and then we can return that down here update points we can spell it update points like so and now this does exactly the same thing as this we take the store we commit a mutation and we pass in the payload p and that's what we did down here okay so now we can get rid of this methods thing as well like so and now all of this should work exactly the same way only now we're using the composition api and doing everything inside the setup hook so first of all we get the store using this use store function then we create this points computed property which is accessing the points from the state on the store and then we create a function called update points we're taking an argument p to be the new points and then we commit a new mutation on the store called update points and pass in the new value of p and remember that is this mutation right here which is updating our state so now we've returned all these down here which is still being used up here so let's save this and give it a whirl all right so we can see the state initially is zero for the points if we add a point it should go up by one each time which it does awesome and if we click this one it goes down by a point each time awesome so this all works so it's doing exactly the same thing only this time we've used the composition api and that use store function from the ux to interact with the store and this is only available in view x version 4 because it was made to be used with view 3 which is heavily involved with the composition api so make sure you're using vuex version 4 in order to use this use store function now for the rest of this series we're going to be using the composition api and using the store this way
Original Description
Hey gang, in this Vuex 4 tutorialI'll show you how to use our Vuex store in the setup( ) hook, using the composition API.
🔥🔥 Get the full course now on Net Ninja Pro 👉 https://netninja.dev/p/vuex-with-firebase-auth
🐱💻 Access the course files on GitHub:
https://github.com/iamshaunjp/Vuex-4-Firebase-Auth
🐱💻 Starter Project:
https://github.com/iamshaunjp/Vuex-4-Firebase-Auth/tree/lesson-1
🐱💻 Vue 3 & Firebase Complete Course:
On Net Ninja Pro - https://netninja.dev/p/build-websites-with-vue-3-firebase
On Udemy - https://thenetninja.co.uk/udemy/vue-and-firebase
🐱💻 Vue 3 Basics Course:
On YouTube - https://www.youtube.com/watch?v=YrxBCBibVo0&list=PL4cUxeGkcC9hYYGbV60Vq3IXYNfDk8At1
🐱💻 Getting Started with Firebase Course:
On Net Ninja Pro - https://netninja.dev/p/getting-started-with-firebase-9
On YouTube - https://www.youtube.com/watch?v=9zdvmgGsww0&list=PL4cUxeGkcC9jERUGvbudErNCeSZHWUVlb
🐱👤 My Premium Udemy courses:
https://thenetninja.co.uk/udemy/react-and-firebase
https://thenetninja.co.uk/udemy/vue-and-firebase
https://thenetninja.co.uk/udemy/modern-javascript
https://thenetninja.co.uk/udemy/d3-and-firebase
🐱👤 Get access to all other premium courses on Net Ninja Pro:
https://netninja.dev/
🐱💻 My Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
Related Reads
📰
📰
📰
📰
The 5 Levels of Front End Engineering (And Where Most Developers Get Stuck)
Medium · Programming
Browser-Based PDF Editing with Vue 3 and pdf-lib
Dev.to · sunshey
Say Goodbye To Electron?
Medium · Programming
Why Vanilla JS?
In the article below, I am sharing my story of building SaaS product in vanilla js and explaining why I decided to go with this approach.
https://guseyn.com/html/posts/why-vanilla-js.html
Dev.to · Guseyn Ismayylov
🎓
Tutor Explanation
DeepCamp AI