vue destroy
The vue destroy instance method can be used to destroy a vue class instance in vuejs. This might not always work out as expected when you think of what might happen when calling a method called destroy, but it will to some extent do just that as the name would suggest.
I think that the vue destroy method should generally not be used, unless I am in a situation in which it would seem that I have to use it which might come up now and then in future projects. I often like to create client systems with a fixed set of resources and then just result those resources over and over again. For example there is having an array and then pushing objects into that array, and purging them out as needed. However I prefer to have a set array of objects, and then have an active property for each object. With that said often I think that I should try using directives like v-if, and f-for before looking into using the vue destroy method.
This vue instance method will trigger the before destroy and destroyed lifecycle hooks when called bring about the end of a vue instance lifecycle.
1 - vue destroy method basic example
Here I have a basic example of the vue destroy method in action. When this example is up and running a step button can be clicked until the kill button is clicked and calls the vue destroy method. Once this happens as expected the click method will no longer work, however the button itself as well as the current count before it is destroyed will remain.
|
|
So the destroy method will do several things that can be thought of as destroying a vuejs instance, but the use of it alone will not do everything that you might expect. So there lets look at some additional examples that have to do with cleaning up the additional things that might remain after calling the destroy instance method.
2 - The before destroy and destroyed Hooks
When a vue instance is destroyed the html for that vue instance will still be there. So there should be at least one additional step to be made when destroying a vue instance and that is changing or removing any html for the instance. One place to do this, and any additional things that should be done would be in the before destroy and destroyed life cycle hooks.
|
|
3 - Conclusion
So far I can not say that I use the destroy method in projects as I often just reuse the same stack of resources over and over again rather than creating and destroying as needed. There is looking into how to mop up everything that might happen when killing a vue instance, but there is also not killing anything to begin with. With any project there is a kind of max number of something that I keep in mind with things including a max number of vue instances for something. So there is just creating that number of instances and just making them active or inactive as needed.