Why didn't this.$nextTick work?

print console.log (this.$refs.vuetree) in mounted, whether it is in the this.$nextTick callback function or not,

clipboard.png

clipboard.png

this.$refs.vuetree.setCurrentKey(100)debuggerdomthis.$nextTick
click:

clipboard.png

clipboard.png

kneel down and thank you.

Mar.09,2021

there is something wrong with the this.$nextTick of this pot. There is something wrong with the code of this.$refs.vuetree.setCurrentKey. You should check the reason why this.$refs.vuetree.setCurrentKey (100) is invalid when you use Element.ui.


  1. find out the execution time of functions executed in mounted;
  2. if there is no call in this.$nextTick, it may be that dom is not finished rendering; however, the official website also says that there is no guarantee that it will be triggered after rendering.

clipboard.png

I suspect that this has changed. Try changing the arrow function


you try to turn $nextTick into setTimeout. Try

.
  

explain
browser for performance, console.log is not Synchronize's. At that moment, it only takes a reference to the object
, that is, the component object is not necessarily created the moment you print it, and I don't know how long it has been since it was printed out. So you can print out the component object
console.log (JSON.parse (JSON.string (vueTree) is the correct
) as for the solution, the setTimeOut upstairs can do it, and recursively determine whether the vueTree exists in nextTick to operate

.
Menu