Recreate a component?

元气小坏坏 提交于 2019-12-24 19:56:47

问题


Is there a way to recreate a component in Svelte?

The context is that I have a component which has already been created. Once it completes its process, I would like for it to be destroyed and then created again. This would restore its properties to their default state, and ensure that the same is done for its nested components.

I imagine that this is technically possible with the existing component methods, but I was wondering if there's a straightforward way to go about it.

As an aside, I'm aware that recreating a component might be inefficient in some contexts. It might be preferable to achieve the desired recreation effect by manually resetting the state of the component and its nested components. For instance, a recursive function could somehow traverse the component and its nested components, and invoke the default data function of each. However, this is not so straightforward, and there are problematic aspects (i.e. computed properties and creation lifecycle hooks).


回答1:


The short answer is no, to recreate a component in its factory-fresh state you would need to call new Thing(...) again.



来源:https://stackoverflow.com/questions/48911519/recreate-a-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!