Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,660 --> 00:00:06,890
In this lecture, we're going to learn how to use the life cycle functions in the composition API,
2
00:00:07,380 --> 00:00:12,910
the process of using a lifecycle function is not much different than what we've been doing so far.
3
00:00:13,260 --> 00:00:15,690
We import a function and then we can call it.
4
00:00:16,350 --> 00:00:23,190
We can use most of the lifecycle functions in the composition API, regardless of what lifecycle function
5
00:00:23,190 --> 00:00:24,450
you decide to use.
6
00:00:24,480 --> 00:00:26,680
All of them start with the word on.
7
00:00:27,180 --> 00:00:33,930
Here are some examples of some of the lifecycle functions available to functions have been renamed the
8
00:00:33,930 --> 00:00:35,280
before destroy.
9
00:00:35,280 --> 00:00:42,180
Hooke has been renamed to before unmount and the destroyed hook has been renamed to Unmounted.
10
00:00:42,720 --> 00:00:48,390
The name changes have been made to more accurately describe what happens to a component when it's removed
11
00:00:48,390 --> 00:00:49,310
from the document.
12
00:00:50,130 --> 00:00:55,500
There are additional lifecycle functions such as the activated and deactivated hooks.
13
00:00:55,920 --> 00:00:56,700
These are called.
14
00:00:56,700 --> 00:00:59,820
If you're wrapping your components with these keep alive component.
15
00:01:00,210 --> 00:01:03,260
It's not common to use these, but they are available.
16
00:01:03,750 --> 00:01:05,400
One last thing worth noting.
17
00:01:05,640 --> 00:01:11,770
The composition API doesn't support the before created and created lifecycle functions.
18
00:01:12,180 --> 00:01:19,440
This is because the set function runs after the before created hook, but before the created hook.
19
00:01:19,860 --> 00:01:25,710
Rather than supporting both hooks, Vue recommends you write your code inside the setup function that
20
00:01:25,710 --> 00:01:27,660
would generally be in these hooks.
21
00:01:29,310 --> 00:01:35,730
Let's use some of the lifecycle functions and the composition API will be working on the app component
22
00:01:35,730 --> 00:01:42,240
file for this example, at the top of the script, Block will import two functions called on before
23
00:01:42,240 --> 00:01:45,630
Mount's and Unmounted from The View package.
24
00:01:48,190 --> 00:01:54,160
We must import the functions if you want to hook into them from the component as a reminder, every
25
00:01:54,160 --> 00:01:57,220
life cycle hook is prefixed with the word on.
26
00:01:57,820 --> 00:02:02,200
We'll use both functions in the setup function, add them at the very top.
27
00:02:09,150 --> 00:02:15,750
We can run code during the life cycle by passing in a callback function, lets pass both hooks and arrow
28
00:02:15,750 --> 00:02:16,320
function.
29
00:02:21,860 --> 00:02:26,720
We won't do anything crazy in the life cycle hooks for demonstration purposes.
30
00:02:26,820 --> 00:02:30,020
We'll take a message to let us know which function gets called.
31
00:02:35,860 --> 00:02:38,170
Let's run the application in the browser.
32
00:02:40,640 --> 00:02:47,390
Open the console and the developer tools will see both messages logged in the console, this result
33
00:02:47,390 --> 00:02:51,410
proves we were able to use the life cycle functions successfully.
34
00:02:51,860 --> 00:02:56,030
Life cycle functions are very easy to use in the composition API.
35
00:02:56,390 --> 00:02:58,490
You need to import them, call them in.
36
00:02:58,490 --> 00:03:01,340
They set up a function and provide a callback function.
37
00:03:01,910 --> 00:03:04,880
The callback function is called during the lifecycle.
38
00:03:05,000 --> 00:03:06,320
There's not much else to it.
3927
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.