The creation and mounting of components that use the cache <keep-alive> at the beginning will be executed the same as the components that do not use the cache, but the components that use the cache will not be destroyed when switching components, and the activated function will be triggered when switching back again. , the deactivated function will be triggered when switching, and components that do not use the cache cannot use the activated function. Simply put, the activated function is a hook function after the page is activated, which is triggered as soon as the page is entered. So when we use component caching, if we want to send a request every time we switch, we need to write the request function in activated, and in created or mounted, it will only work when the component is loaded for the first time.
Here are the usage details:
<keep-alive :include="['DDD']">
<router-view></router-view>
</keep-alive>
//
activated() {
console.log("hello")
},
deactivated() {
console.log("OvER!!!")
},
Comments
Post a Comment