Vue: $destroy() a slot component , the component will not be removed from DOM

Created on 23 Mar 2017  路  2Comments  路  Source: vuejs/vue

Version

2.2.4

Reproduction link

http://jsbin.com/canofepuyi/edit?html,console

Steps to reproduce

two compoennts: comB and comA, comA as a slot into comB, when use $destroy() in comB to destroy comA, the instance is removed, but dom not.

* in Vue1, it worked. *

What is expected?

dom removed too

What is actually happening?

dom not removed

Most helpful comment

In Vue 2 you should avoid directly manipulating slot children. Instead of $destroying it, you should have a v-if controlling the slot component in the parent:

<comp-b @close-a="showA = false">
  <comp-a v-if="showA"/>
</comp-b>

All 2 comments

May be I have the same problem !
I use slot too锛寁ue2.2.4
sometimes ,$destroy works well ,but sometimes not , and destroy hooks not triggered too

image

In Vue 2 you should avoid directly manipulating slot children. Instead of $destroying it, you should have a v-if controlling the slot component in the parent:

<comp-b @close-a="showA = false">
  <comp-a v-if="showA"/>
</comp-b>
Was this page helpful?
0 / 5 - 0 ratings