vue life cycle mounted and activated use, stepping on the pit

activated

Speaking of activated , you have to mention keep-alive , you will call it when you switch out and cut out. (You can understand it as a life cycle hook function, and the usage is the same)

mounted

It refers to the call after the instance is mounted. If there is no keep-alive, the component will be triggered every time it is switched back, but keep-alive will cache inactive component instances, so it can be said that it will only be triggered once. So often some data requests need to be written once here, and once in activated, to ensure that you can request new data when you come back from stray.

Step on the pit

1. There is a keyword here as an example, which means that if you use $refs, you have to pay attention.
2. Mounted is executed first, and the two are executed together when first entering
Insert picture description here

postscript

keep-alive的运用非常非常非常多。

https://cn.vuejs.org/v2/api/#mounted

Guess you like

Origin blog.csdn.net/weixin_45629623/article/details/107542066
Recommended