Тёмный
No video :(

Easy Way to Understand the VueJS Component Lifecycle Hooks 

edutechional
Подписаться 42 тыс.
Просмотров 23 тыс.
50% 1

In this Vue.js tutorial, we are gonna take a deep dive and look at the lifecycle hooks provided from the Vue framework.
Now, we're going to analyze the lifecycle diagram, and then go and implement this into a Vue application. We're also going to extend it, because this lifecycle set of hooks and what they list in the documentation is helpful for understanding, because it's a helpful visual. But I think that it's missing a couple of elements that I personally have had to implement into my own production Vue applications, and so I think it will help for you to see those as well. So we're gonna walk through quite a bit of material in this guide.
So I have a Vue application running right here in the background, and we're going to be looking primarily just at a few different components. So we're going to be looking at a dashboard component, a Vue component right here, and then that has the nested login component.
And so what we're gonna be doing isn't as much building in this guide, we're instead gonna be looking and analyzing to see how exactly the lifecycle process works.
If you are not aware of this, if you've never heard of the lifecycle, or if you're just trying to understand it for the first time, the best analogy that helped me is trying to compare a Vue component to us humans.
So as a human, we are born, we go through different stages in life, and then, even though it may seem dark, we all die at some point. Well, that's the way a Vue component works too. A Vue component is born. We say that a Vue component is created, then it has a number of things happen. It has changes go on, such as data changes, and updates, and those kinds of. And then at a certain time, it also dies, or we say that it is destroyed.
So what we can do with Vue is we can actually listen for and capture those events, each one of those, from created all the way through destroyed, and then update the application based on the state of the component.
So hopefully that starts to make sense. But what really help understand the lifecycle hooks and the entire process was really just getting in and implementing each one of the methods.
I'll provide in the show notes a link to this documentation, 'cause that can help to have a visual. But I think what helps the most is just going in and writing the code.
So I'm going to switch back to our application here, and then opening up Visual Studio code here, you can see that we have our homepage component, which is just rendering out some content, and then our login component. And that's pretty much it. That's pretty basic right now.
So we're gonna start in the dashboard, and I'm gonna go out, and I'm gonna start listing some of these hooks. Now, right now we have a pretty basic setup where we have our data function, then we have a list of the components that we are registering, and then we have one custom method. I usually by convention place these lifecycle hooks right above the methods, I like to have my methods at the very bottom, so I know exactly where they're at. But you could technically put these anywhere inside of the script tag, as long as it's right after the default curly braces.
Now, I'm going to just list off a couple basic ones here first. So I'm gonna say beforeCreate(), and it is a regular method, so you have to have the parens right after it. And then I'm going to console.log and then say beforeCreate, just so we know exactly what's happening here. And then for this one, I'm also gonna say this afterwards, 'cause this can be really helpful in understanding what we're referencing. And then make sure you put a comma there. And then after that say created.
Now, unlike some other methods or names inside of Vue, these are reserved words. So before create is something provided by Vue directly. Created is something provided by Vue. So these are reserved and they are names and functions that are built directly into the Vue source code.
I'm going to copy this console log here, and then change this to say created. And I'm not gonna pass in this or else it'll make the output a little bit messy, and you'll notice that the this that it's referencing is gonna be the same for all these elements.
So let's just start with these two, and then we'll get into some of the other ones after this. So switching back to the browser, I'm going to clear the output, hit refresh, and now you can see that we have some console log statements here. We have before create, and then created. So both of these worked. So they were triggered. Notice that we didn't do anything. All we did was we listed them out inside of the component.
#vuejs #javascript
Full guide and code:
www.crondose.c...
Follow me:
Twitter: / jordanhudgens
Instagram: / jordanhudgens
GitHub: github.com/jord...

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 44   
@fotiem.constant4948
@fotiem.constant4948 2 года назад
Very detailed and easy to understand. I remember having a hard time understanding these lifecycle hooks when I was getting started, it has cost me a lot trust me... There are a lot of stuffs which I was doing it natively, putting them in methods without knowing Vue already has an implementation of those with the hooks. Thanks a million man. Learned a lot from this video.
@AndersonSilvaMMA
@AndersonSilvaMMA 5 лет назад
I really want to understand vue. But I couldn't find any good video that will make things simpler. Your video is doing this. Thank you! Can you please make a series on Vue? Thanks!
@edutechional
@edutechional 5 лет назад
That's what I'm working on right now. I'm glad that you're finding these videos helpful!
@bobDotJS
@bobDotJS 4 года назад
Best Vue lifecycle hook video on YT
@edutechional
@edutechional 4 года назад
Thanks!
@meghadeysarkar6730
@meghadeysarkar6730 3 года назад
Thanks for making understanding simpler. Please make more tutorials on Vue js full course.
@youmnaification
@youmnaification 5 лет назад
Thank you for this video. These are the type of videos that I like to watch. Plz more videos on VueJS deep dive.
@edutechional
@edutechional 5 лет назад
Thanks so much, will do!
@sudharakafernando4391
@sudharakafernando4391 Год назад
Thank you for the amazing explanation !!!
@blacklotus1606
@blacklotus1606 5 лет назад
Damn Man, you made My Life Easier, Plz Do more Vuejs stuff, absolutely Love it.
@edutechional
@edutechional 5 лет назад
I'm working on a new Vue course right now!
@RabbitWerksJavaScript
@RabbitWerksJavaScript 5 лет назад
Well done, very detailed and informative. Love Vue. :) lifecycle hooks are simply the greatest.
@edutechional
@edutechional 5 лет назад
Absolutely, they're very helpful!
@OFWGKTAxGOBLIN
@OFWGKTAxGOBLIN 5 лет назад
Very clear and concise tutorial
@DiDGeek
@DiDGeek 2 года назад
very detailed and helped me lot to understand lifecycle hooks. thanks:)
@rickyu1978
@rickyu1978 5 лет назад
very clear and easy to understand tut on lifecycle hooks. keep vue tutorials cumming. btw which hook is best for running async code, for example i want to fetch a get request in the background , but have the page continue the load. it is not data dependent.
@Salamaleikum80
@Salamaleikum80 3 месяца назад
Does update fire when you are interacting with the dom or when data changes within the component?
@Indialoves1
@Indialoves1 4 года назад
hats off to you brother, very well explained...
@edutechional
@edutechional 4 года назад
Thanks a ton
@ComisarioLobo
@ComisarioLobo 5 лет назад
Hi, nice video, could you please elaborate a bit more related to use of async and await and also localStorage inside these life cycle methods?
@androidocean2796
@androidocean2796 4 года назад
You just earned a subscriber. Thanks for video. It's amazing
@edutechional
@edutechional 4 года назад
Thanks for the sub!
@andristefanus
@andristefanus 2 года назад
thanks for the real world example, most of the tutorials are just throwing console logs
@eugeniogonzato
@eugeniogonzato 5 лет назад
This video is amazing thanks!!
@edutechional
@edutechional 5 лет назад
You're welcome!
@michaelmudge3080
@michaelmudge3080 3 года назад
beforeRouteEnter is specifically a vue router method, right?
@pabloverdasco9579
@pabloverdasco9579 2 года назад
Well done, nice video, thanks for the info
@mdbashirfardoush5624
@mdbashirfardoush5624 4 года назад
Excellent explanation.
@edutechional
@edutechional 4 года назад
Glad you think so!
@louieaniez3948
@louieaniez3948 2 года назад
How will I know which data is updated inside beforeUpdate and updated hooks?
@jason0ng
@jason0ng 4 года назад
Excellent tutorial, thank you.
@edutechional
@edutechional 4 года назад
Thanks for the kind words!
@rakeshsathya9926
@rakeshsathya9926 4 года назад
Very nice bro...
@edutechional
@edutechional 4 года назад
Thanks!
@genaxie8480
@genaxie8480 2 года назад
well explained.
@paljinder3
@paljinder3 2 года назад
excellent !🥰
@TAYON94
@TAYON94 4 года назад
Great video.thank you very much you really are a life saver ❤️
@edutechional
@edutechional 4 года назад
Thanks for the kind words!
@AJ-rs3ub
@AJ-rs3ub 5 лет назад
please make a series of Vue with rails!
@edutechional
@edutechional 5 лет назад
I am working on it!
@Bawaromerali
@Bawaromerali 4 года назад
Thanks , What about Computed ?
@nicholasy6371
@nicholasy6371 5 лет назад
very good, please make more about vue-router
@edutechional
@edutechional 5 лет назад
Thanks, and that's on my list!
@scottbernard6685
@scottbernard6685 5 лет назад
Hey I just want my old Videos
Далее
Vue.js: The Documentary
34:45
Просмотров 1,5 млн
Vue 3 - What's New? What Changed?
30:47
Просмотров 131 тыс.
🎙ПОЮ ВЖИВУЮ!
3:17:56
Просмотров 1,5 млн
The Trick to Understanding Scoped Slots in Vue.js
9:59
Vapor: The Future Of Vue
21:27
Просмотров 118 тыс.
Vue.js Scoped Slots & Renderless Components
22:19
Просмотров 14 тыс.
A Better Way To Organize Components In Vue
10:10
Просмотров 20 тыс.
Vue JS Directives Tutorial
20:59
Просмотров 1,1 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 354 тыс.
Vue JS 2 Tutorial #26 - Life-cycle Hooks
9:18
Просмотров 99 тыс.