Vue 3 Composition API Introduction [FULL TUTORIAL]
HTML-код
- Опубликовано: 10 фев 2025
- The Composition API is THE biggest new feature introduced by Vue.js 3. It's 100% optional but definitely worth a closer look as it allows you to write leaner, more elegant code - especially in bigger apps and components.
Starting Code: github.com/aca...
Finished Code: github.com/aca...
Learn ALL about Vue 3 (incl. deep dives into the Composition API) with my fully updated course: acad.link/vuejs
Also learn about all other import changes introduced by Vue 3: • Video
Check out all our other courses: academind.com/...
----------
• Go to www.academind.com and subscribe to our newsletter to stay updated and to get exclusive content & discounts
• Follow @maxedapps and @academind_real on Twitter
• Follow @academind_real on Instagram: / academind_real
• Join our Facebook community on / academindchannel
See you in the videos!
----------
Academind is your source for online education in the areas of web development, frontend web development, backend web development, programming, coding and data science! No matter if you are looking for a tutorial, a course, a crash course, an introduction, an online tutorial or any related video, we try our best to offer you the content you are looking for. Our topics include Angular, React, Vue, Html, CSS, JavaScript, TypeScript, Redux, Nuxt.js, RxJs, Bootstrap, Laravel, Node.js, Progressive Web Apps (PWA), Ionic, React Native, Regular Expressions (RegEx), Stencil, Power BI, Amazon Web Services (AWS), Firebase or other topics, make sure to have a look at this channel or at academind.com to find the learning resource of your choice!
7:04 Ref (Reactive data initiation)
9:40 Computed props
11:05 Methods
16:25 Inherited props
18:35 Emitting events to parent component
19:34 Watchers
thank you.
Thank you very much.
To me, the simplicity of the Options API is the magic of Vue, so I will stick to that.
I always look for you whenever see new thing happening in React, Vue and Angular and javascript also, what a way you teach i love it. I became a developer in few month by purchasing your courses, you are the only one who has changed me to become a good developer, keep it up best support from us.
Was waiting for max to release some beautiful content on vue3 ❤️
'Max' writes with uppercase, not lowercase ;)
The world is so small 😆😆
Max, I am an IT professional. Last year my income was only 3.25 lakhs (INR) in a year. I started watching your course, learned, practiced, and worked hard. Now as a result I am earning more than 30 lakhs (INR) per annum. It's just only because of you. No words can express how grateful I am. #therealteacher
Please don't compare you're luck on this earth with the eternity.
Jesus Christ died for you're sins and if you would get him, you would never compare a man with God.
@@Kingside88 WTF
@@Kingside88 cringe
@@Kingside88 In the grand scheme of things, you could say that God (or first cause/luck/whatever) "pushed" that first domino brick that would eventually help Sam out through the videos of Academind, so in that sense, I agree with you.
As for Jesus Christ being God, doesn't that contradict your last statement of "you would never compare a man with God"? If Jesus Christ behaved, acted, spoke, ate and prayed just like any other human being (or any other prophet with miracles), how could you possibly compare this man-like created creature with the uncreated and eternal God?
@@zainmushtaq4347 Jesus is not half human and half God. As soon as he born he became a full human. And still was God and son of God. And he is still both. You can not find anybody to compare with him.
This video is still useful today!
I found it after spending a week spinning my tires learning Vue. I bought the course on Udemy for $15 and Section 19: Replace the Options API taught me everything I needed.
Thanks for taking the time to build this series.
I made my company to buy the IONIC-React course thanks to the 3 hours video, I was a wonderfull work of art, I'm still following it in your page.
I love your videos man, I was struggling to understand the Vue 3 Composition API and this just helped me finally understand it!
I'm saving up to buy your Vue Course now (I already have the PWA and Angular ones)
I've been struggling to adopt Vue 3 as i'm working on a PWA game project and wanted to adopt the next version. I normally use jQuery or vanilla JS for projects, not having used Vue or React before. Thank you for uploading this video. It's helping me understand everything just a bit better.
This is the best video on how to migrate from Options API to Composition API. Thank you so much for this. Irony is that I already have bought Udemy course on Angular and Vue from you but I usually learns from such short video's here and there 😅
Very good and clean course. I did totally understand everything neccessary under 30mins in order to port/migrate from OPTIONS to COMPOSTION API! Thumbs up
Oh, didn't know you updated the course! That's awesome! Maybe send a notification in Udemy or email to the users for others who might have missed it too. Can't wait for Nuxt 3 to be released too. Thank you for the video and all the efforts, cheers!
An announcement was sent today to all enrolled students.
@@academind Indeed i see the announcement now, it just doesn't appear in the notifications in Udemy (like usually) for some reason.
I wasn't aware about Max...but after I have gone through this post....It's fab!! I surely started following him in Udemy for other courses. Nicely explained the new concept of composition api
so far this is best tutorial I see in youtube. You explained it pretty simple.
As always, Maximilian is the best in explaining everything :)
Academind beg/implore you launch a "Complete web developer bootcamp" course from zero to hero. It's going to be a "best seller", it's much needed.
Well Max after being a self taught dev for a year and following mostly your courses i've got hired in honestly the best company i could ever find. I wonder if i should send you at least a bottle of Prosecco. Do you like white wine? 😂
I love wine in all colors :D
Congrats on the job - that's really awesome to read!
Once again, guaranteed Maximilian quality! 👌
Came across you video and really love the way you explain things. Will certainly get your course now.
Was just waiting to ask the doubt of how this kind of compositions helps in improving the application code. And, you just circled it out explaining that in the last 5 mins.
Hi Maximilian,
I am watching your Vue course on Udemy, so thanks for it, it's a very good one.
Now I am in the Composition API section, and I have such question:
I have a lot of experience with React+hooks, and when in Vue I see such things like:
1) we have both 'ref' and 'reactive';
2) we need to pass the whole 'reactive' object to make it reactive in the template;
3) we need to wrap 'reactive' object with 'toRefs' to make its values be reactive;
4) in the child component we can mutate the 'ref' value injected from the parent component;
5) when I use some prop in the 'setup' method of child component I should remember whether it is a 'ref' or 'reactive' to know whether to use it with '.value' or not;
Compared with React, the Vue solution seems to be not so mature and looks more like a workaround, because in React it is solved with a single 'useState' and works much better and obvious:
- we have "[state, setState] = useState(...)" and with 'setState' we can do any change no matter whether the value is an object or a primitive and it will be reactive;
- and if talking about the item 4) we just pass via props or context the 'state' if we want it to be read-only, or 'setState' if we want to update the value
What do you think about this? What is your personal opinion about these things in Vue compared to React?
BTW. I saw that in Vue docks they compared Vue composition API to React hooks and said how the first is better in terms of performance and etc., But still, IMHO, the developer experience provided by Vue Composition API is not the best one.
I‘m coming from Svelte and from that perspective it‘s inadequately solved in both. I have needed the last few days to wrap my head around all those things you mentioned and I‘m still having a problem I can’t figure out.
This info is prime, and your video is superb... although I am getting some serious Nick Kroll vibes, vocally. It's kinda like learning to program with Prof. Poopypants from Captain Underpants. Love it!
It's astonishing to me how Max's brain is able to hold so much information.
I think quite often when watching his videos!
codes are written in his DNA!
This "hooks" thing is what really blew my mind
Thanks sounds very similar to React hooks and the last example which he mentioned sounded like a custom hook. Nice
I cackled at the app filtering out any React and Angular related goals lmao
Comprehensive explanation, thanks for that!
This is basically how knockout works. Create standalone observables, computeds and method, and expose what you want to the view. Knockout is ofc lacking things like the vdom and other things, but at the core this is how the reactive/observable model works.
Thank you for the introduction, it was very helpful. 💕
Awesome as always!
New APIs use seems to be if you don't want to make components out of everything. I can see a good use in combining the two methods in 1 component. Composition API to share code, and options API to effectively extend the shared code.
But how exactly would you share some code with the composition API? Is the assumption that you will import one more more methods / variables from the returned 'setup' object into other components?
Maybe it's just me but I don't see a ton of benefit to this if I still have to be import more stuff (ref), extracting their values (.value), etc. I guess I was expecting something a little more impactful than this.
Excellent video! Love the way you explained things. Many thanks Max!
Thank you man, appreciate the video!
Thanks Max! Has vue gain more popularity? these days it's hard to find new content related to Vue and basically it's just React. Also, any thoughts on NestJS as your next course? Lots of buzz around that framework. Supposely a better version of express.
Finally I understand it! Thanks
So no Angular and React goals? :D I have listened to your Vue course and it is the best that I found. After the course I was looking for information how to manage code for bigger Vue applications, but there is so little information out there, or maybe I was looking in wrong places. I also did not find any courses online that would give me that knowledge. I would really appreciate if you could create a video/extra chapter in your course with tips/tricks for bigger applications. And thanks a lot for all your hard work!
Perfectly explained, thanks!
Hey Max, now that Vue is becoming the greatest FE framework (My opinion of course) is any plan on a new Vue 3 course with typescript + end to end and unit tests ?
Not right now. Maybe I can add sections to the existing course - not in the next weeks though.
@@academind yeah just add 2 sections of testing and typescript in the existing course! That would be awesome! Also thanks for updating your course!
@@TheStefanos939 The documentation is really great. You should also check out lmiller1990.github.io/vue-testing-handbook/v3/ for a Unit Testing intro.
Finally i get this! Thank you bro!
In big app good aproach to make search mixin with data, methods etc for search, filter mixin with data, methods etc, check premissions mixin etc
Awesome content of vue 3 at the same time. Loved the content.
Thanks man, I know understand Vue composition Api
Great Tutorial!
Thanks for this great tutorial
Interesting changes. Are there any benefits to using a setup() instead of the separate data(), computed() and methods()? Almost seems a bit more complex than the separate functions. Also not a huge fan of having to use refs for all data variables and having to add value when using them.
Sent this before I finished the video. I see how it can be useful to simplify the logic used by multiple components.
@@willfranklyn2 he elided a bit but some people actually prefer the reactive() function instead, which is meant to wrap objects. So something like
const x = ref(1);
x.value = 2;
can be replaced instead with
const data = reactive({ x: 1 });
data.x = 2;
for roughly the same effect. Of course there are some pros and cons for each, but for simple components they should be mostly interchangeable.
My thoughts exactly. But even after watching until the end I am still not sure that the benefits outweight all the extra work and added complexity. It's a bit dissapointing that the Vue team decided to follow the hooks trend introduced by React instead of coming up with a cleaner solution.
great explanation
Thanks Max! Your explanation is amazing.
thank you !😃😃
very well explained! good job 👍
After long long time
TY bro 👍🏻
Great tutorial MAX. Posting less on RUclips lately.
Great video 👍
Perfectly timing! heheee
Thank you Max!
Now use typescript and tsx and you have a beautiful setup ;)
Now when Vue 3 is out, is there a plan maybe for MEVN course Max :) ?
I got no concrete plans but it's something I'd like to do, I can say that.
i think composition api might be good, but for me options API is an organized and simpler to read and use;
so did you get what composition api provides ? you just talked about replacing old with new, but what this new bring to the table ? I've seen only refactoring the code, but nothing valuable on this composition api, but this might be my personal view on this, sorry
Can we expect some php course on academind any soon?
It would be nice a video using instead of the setup() function
Hey Max, are you planning an Ionic/Vue course like the really good React course?
Options API is much more intuitive and causes less pain.
Well done
Hello Max!
Any idea of sharing this Vue 3 course on Udemy ?
Awesome content
Max, do you prefer the composition api or mixins for code reusability?
Can you please do more videos on flutter like to add the name of the application with code etc like how to publish the application too...
very useful tutorial. very nice and then subscribe to your channel
Anyone else prefer the options API like 10,000 times more than the composition API? Updates to frameworks should make coding in them LESS verbose, not more.
Composition API is much much much better than options API for 1 simple reason - all of the logic related to certain part of the component can be grouped in one single compact place so you don't need to scroll back and forth all the time so understand how certain part of the component works.
@@k.safonov That’s a reason I actually don’t like the composition API. I like data in data, methods in methods, computed in computed. Also, I HATE having to import ref, define ref and const for everything… feels like old vanilla JS.
That exactly why I like it. It’s a lot more like JavaScript, a lot less like a framework.
@@blakerunyon09 sounds like you want React
@@rajikkaliNo he wants a better React. Secondly removing this keyword from code is an improvement friend. this keyword sucks in js
Well explained. Good work! Feedback for improvement: Think about working on
pronunciation (improve the "chewing gum" english and unrelaxed way of talking). I like the content of Max a lot, but unfortunatelly I just can't listen to this pronuncation for a whole course (eg on Udemy)
Hi Max, are u going to update the most successful vue js course on udemy with latest vue js 3 changes?!
I hope so as usually expected ☺️🙏🏼
I just updated the course to Vue 3.
Is this easier? Seems like more steps?
Edit: nvm watched the whole video, this is beautiful, vue for life💚
someone could explain to me why is it better using this setup() where i have to import everything one by one to use the damn thing instead of using the normal data, computed, methods etc?? instead of making things easier i find this to be much more of a pain in the ass personally and yet have not found any advantages
I want to tripple like this tutorial xD
Ahhh Vue Hooks I see :D
great jop
do you have any plan for golang ?
Hi Max! I would like to know if you can make a shorter version of React course, focusing more on the most important aspects of it?
Great video! Quick question.. Can I use a hook in app.vue if I convert it to composition api? Right now I find I need to call the same code at app start up as when navigating to a component. I've been using mixins for this.
Hey Max! I have a request to you...please make a course on web design with HTML5 & CSS3 for beginners...actually the courses of web design on udemy are old and not good as I want
Very good
please share your course link?
First comment from my side Max
i download codes and opened it in visualstudio vue code's color is gray i dont know why please help me
how to Composition API use watch like this:
watch: {
'fullname': {
deep: true,
handler(val) {
console.log(val)
}
}
}
Academind, Can you tell me what software you use to record parts of the video that look like a presentation? With beautiful tables, diagrams, images, text, etc.
PowerPoint ;)
Vue 3 honestly seems like a step backwards to me. Less seperation of concerns, more ambiguous data access (having to use .value on a ref), all seems a bit odd. Personally I like simple Vue 2 with vuex for state management, and the built-in event bus for broadcasting actions. Much simpler.
Hey Max,
I missed out early when membership launched. Is it possible to get the yearly membership at introductory price in near future?
Current price is a bit stretched for me due to higher currently price deficit between USD and INR.
Thank you.
hi, please create a video about jobs queue with nodejs or express..
thank you.
Hey Max, Thank you for such an amazing tutorial. Can you help me out with a live location tracking application(idea about to go with it )?(using node js as backend)
Hi,
I would like to ask why context doesn't have a root in my vue 3 setup. when i console.log (context) it only displays emit, slot and attr. there is no root in there. thanks
I really don't fully understand the benefits of this composition approach.
How on Earth would this make code-sharing easier? The mixins for the options API seemed pretty darned convenient...
Super!
But that userSearch could not be imported either without the composition API? anyways?
First 🧨🧨
I m first.. 😀😀😀
@@nasreenustad7658 100.00%
@@RedBerryTV hey I m just kidding..
@@nasreenustad7658 me too🤣
Thanks max
Why do need a key during the export? Couldn’t you just export the object without that?
This just seems worse in every way.
One of the best things about vue is that if you follow the established design patterns, everything falls into place. But with this, it seems like you get a lot of freedom, but this means you have to explicitly define absolutely everything. The new refs system seems very strange as well. Vue properties were already plenty reactive anywhere in the component. I do like the ability to reuse code easier, but I think mix-ins do that just fine.
There is toally oom for improvement with the options API in-in of itself, but this ain't it, chief.
Mixins are very confusing to use once there are more than 1 mixin... they can override each other depending on the import order, and there is no hint as to which mixins the data / computed / method came from.
That bit about renaming the first function argument to "_" so we don't get complaints about unused arguments. Eh? What's powering that? That's not standard JS behaviour so is that some linter or Vue CLI itself enforcing that?
That's his project setup, much probably coming from an ESLint configuration like eslint-config-airbnb.