2.4.1
https://codepen.io/zhangzhuo/pen/pwYgdW
Open https://codepen.io/zhangzhuo/pen/pwYgdW and click 'click it', see what happen in console.
console.log should show the size of the element.
Got '{width: 0, height: 0 ...}'
The child element will removed from document before 'beforeDestroy' called, is this intended or?
I got kind of a similar situation.
I got two components:
ParentComponent
--ChildComponent
The ParentComponent is deleted when a v-if condition is met. This triggers the 'beforeDestroy' on the ParentComponent and seems to remove the DOM elements within the ParentComponent (and thus the ChildComponent). After that the 'beforeDestroy' on the ChildComponent is triggered, in here my ChildComponent looks for something in DOM which isn't there anymore.
Shouldn't the ChildComponents 'beforeDestroy' be triggered first? Or is there a better approach to solve this problem?
+1
@Zhangdroid @bartdonninger I've been troubled by this problem for many days
This is actually expected because the element is no longer in the DOM when the beforeDestroy triggers. Fortunately, in that specific scenario, when you need to get an element size, you can append it back to the document (or any other element) and compute sizes before removing it: http://jsfiddle.net/posva/3mrer9a2/
@posva Thanks for your reply, but I still got some trouble.
I try to build vue version of react-overdrive, it need to get the size and position before component destroyed, is there any way to get it? Thanks again.
@Zhangdroid Hey, buddy, I'm trying to build Vue version of react-overdrive too
Most helpful comment
I got kind of a similar situation.
I got two components:
ParentComponent
--ChildComponent
The ParentComponent is deleted when a v-if condition is met. This triggers the 'beforeDestroy' on the ParentComponent and seems to remove the DOM elements within the ParentComponent (and thus the ChildComponent). After that the 'beforeDestroy' on the ChildComponent is triggered, in here my ChildComponent looks for something in DOM which isn't there anymore.
Shouldn't the ChildComponents 'beforeDestroy' be triggered first? Or is there a better approach to solve this problem?