Skip to main content

Two lifecycle hook functions activated and deactivated in Vue routing

 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

Popular posts from this blog

What is the difference between the box-size property content-box and border-box in the css box model?

 The box model is a very important concept in CSS layout, it includes content area, padding, border, and margin. Box models can be divided into two types: standard box models and IE box models. The box model, as the name suggests, is used to hold things, and the things it holds are the content of HTML elements. In other words, every visible HTML element is a box.

Js uses recursive way to traverse the dom tree to dynamically create element nodes

 What is a dom tree? In short, DOM is the Document Object Model, which provides a structured representation for documents and defines how to access the document structure through scripts. DOM is composed of nodes. After the HTML is loaded, the rendering engine will generate a DOM tree in memory based on the HTML document. This article uses a small case to traverse the dom tree recursively. The core of the method is to determine whether the incoming data is an array, and then traverse the root node. Note that there must be an end condition when using recursion.