how can component delete itself in Vue 2.0

后端 未结 4 1025
有刺的猬
有刺的猬 2021-01-03 18:47

as title, how can I do that

from offical documentation just tell us that $delete can use argument \'object\' and \'key\'

but I want delete a component by its

4条回答
  •  感动是毒
    2021-01-03 19:17

    No, you will not be able to delete a component directly. The parent component will have to use v-if to remove the child component from the DOM.

    Ref: https://vuejs.org/v2/api/#v-if

    Quoted from docs:

    Conditionally render the element based on the truthy-ness of the expression value. The element and its contained directives / components are destroyed and re-constructed during toggles.

    If the child component is created as part of some data object on parent, you will have to send an event to parent via $emit, modify (or remove) the data and the child component will go away on its own. There was another question on this recently: Delete a Vue child component

提交回复
热议问题