Add dynamically Lifecycle Hooks using Vue.js 3

Asked

Viewed 15 times

0

Good afternoon.

I have some components in Vue.js on npm and I received a request to put compatibility with Vue.js 3 (at the time these components were made with only version 2.x in mind).

The problem is that, at the moment, I cannot migrate these components to version 3.x and let version 2.x die, I need them in some places with version 2.x working yet, so I wonder if anyone knows of any way to let it work in both versions.

One of the problems I’m having is that they renamed the methods of clean-up, such as, for example, destroyed and beforeDestroy for unmounted and beforeUnmount.

I thought I’d put it on created checking the version of Vue.js that is being used, and if it were 2.x would place beforeDestroy, otherwise I’d put beforeUnmount, but I couldn’t do it dynamically, since these are Lifecycle Hooks from Vue.js. I used to be able to do this using this.$once('hook:beforeUnmount', () => ()), however they were removed in version 3.x, and I did not find anything compatible with it that works in both versions.

I have researched some forums, issues and documentation, but so far I have found nothing of this kind. I don’t know if everyone is migrating their components to Vue 3.x, forgetting about Vue 2.x or what they are actually doing.

If anyone knows anything that might help, I’d appreciate it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.