How to refresh the specified subcomponent in vue, reset the component, force refresh, and reload the subcomponent: key = "value"

Preface:
The effect I want to achieve is to reload this subcomponent where I need it, and perform a forced refresh effect.

Step 1: In the template, find the component you want to refresh
insert image description here

  <组件名字 :key="变量名></组件名字>

Step 2: In data, define variables
insert image description here

Step 3: Add this sentence where you want to refresh this component

this.item = new Date().getTime()

Implementation instructions:
By changing a variable, the forced refresh of the component is realized. As long as the value of the key changes, the component will automatically refresh, so the value of the key can be of any type.

The role of the key in vue is mainly to update the dom efficiently, it can also be used to force the element/component to be replaced instead of reusing it, and the life cycle hook of the trigger component is completed to trigger the transition.

Guess you like

Origin blog.csdn.net/weixin_47336389/article/details/127986754