Home > other >  Components of the definition of internal ref in less than mounted hook
Components of the definition of internal ref in less than mounted hook

Time:05-18


Component inside an element of the a1 defines c ref="test1", but can't find in c mounted hook c. $refs. Test1
When mounted in no c. $refs. Test1, but after mounted (should be page thoroughly after initialization), is there,
Because the c $refs. Test1 do some event binding operation, what should be in time to catch safely c. $refs. Test1?

CodePudding user response:

What you need is the conclusion,
V - if="false", the DOM node does not exist, nature does not (because this element never render to the DOM tree),
V - show="false", the DOM node has been rendering, just display: none,
In the official documentation describing the difference:



Cn.vuejs.org




Conditions for rendering - Vue. Js

Vue. Js - The Progressive JavaScript Framework

CodePudding user response:

Well, is the conclusion, finally know the reason, thank you very much??

CodePudding user response:

Father of a1 component c is, according to certain conditions and control the visibility of c is visible a1 is always visible,

CodePudding user response:

Try once, after mounted beforeUpdate can be found in c. $refs. Test1,
But this is not the desired results,

CodePudding user response:

That is not visible when c a1 is invisible, then a1 is not visible when mounted the trigger?

CodePudding user response:

When mounted trigger a1 also can not find,
However, hit a breakpoint, found that, when mounted, can be from c. $el. Children find a1 inside,

CodePudding user response:

Tried several times to find such a rule:
C the visibility of the v - if control, can not find in mounted c. $refs. Test1
With v - show, is ok,

CodePudding user response:

 silentdepth:

That you should watch the v - if conditions, combined with $nextTick () operation the DOM,


The idea is quite good ^_^
However, a little worried that v - if if repeated switch, will not lead to do processing was accidentally executed multiple times and what's the problem (had meant to be mounted inside of the c. $refs. Test1 binding onchange events), have taken the time to try,

CodePudding user response:

Try once, feasible!!

CodePudding user response:

However, this leads to a lot of the time can only use v - don't show, but with the v - if,
V - if='false', wish can even mounted trigger,

CodePudding user response:

The a1 elements are always visible HTML element? If so, capturing the mounted can; If not, just like mounted it doesn't matter,

CodePudding user response:

What am I doing this page has some other jquery already exists for processing, and to compare the trouble is that the jquery will operate my components inside the element (c. $refs. Test1), in order to detect the jquery changes and response components, even with this series of questions,

CodePudding user response:

Events, write directly to the template is not good, why do you write in the way

CodePudding user response:

- if not, v and v - show the biggest difference is that switching cost is different, this is the performance aspects of things, if one of your logic is dependent on v - if the result of control, then you should watch the v - if conditions, combined with $nextTick () operation the DOM, struggle with mounted a little partial,

CodePudding user response:

That still use v - show, guarantee the stability of the DOM structure

CodePudding user response:

Aha!!!!!!!!!!!!!!!
  • Related