Jump to content
Search Community

Reuse components in Vue

Liam_hyperisland test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

I had to edit the post because I found that the React x GSAP documentation is quite helpful for Vue applications as well.

What I'm trying to recreate is a Vue version of the 'Reusing Components' example found in the React documentation. Can anyone confirm whether my Vue version is equivalent to the React example?

 

Reusing Components (The only difference is that I'm using a timeline and reusing two components)

 

Official React example of Reusing Components

 

Thank you

 

See the Pen RwVBWGW by GreenSock (@GreenSock) on CodePen

Link to comment
Share on other sites

  • Solution

Hi,

 

Indeed passing the timeline or a method to add to that timeline as a prop is a good approach as long as all the components are direct children of the main one.

 

But if for some reason you have more nested components, then I'd suggest using a Vue Composable for that:

https://vuejs.org/guide/reusability/composables.html

 

Unfortunately I don't have time to create simple demos for both approaches now, but you could check this demo that shows how to use a Composable with GSAP instances:

https://stackblitz.com/edit/vitejs-vite-w8wtpj?file=src%2Fcomposables%2Ftransition-composable.js,src%2Fviews%2FScrollView.vue,src%2Fviews%2FLayersView.vue

 

I'll try to get something done in the next few days in order to provide a working example of using a composable for this. Hopefully this helps for now.

 

Happy Tweening!

Link to comment
Share on other sites

10 hours ago, Rodrigo said:

Hi,

 

Indeed passing the timeline or a method to add to that timeline as a prop is a good approach as long as all the components are direct children of the main one.

 

But if for some reason you have more nested components, then I'd suggest using a Vue Composable for that:

https://vuejs.org/guide/reusability/composables.html

 

Unfortunately I don't have time to create simple demos for both approaches now, but you could check this demo that shows how to use a Composable with GSAP instances:

https://stackblitz.com/edit/vitejs-vite-w8wtpj?file=src%2Fcomposables%2Ftransition-composable.js,src%2Fviews%2FScrollView.vue,src%2Fviews%2FLayersView.vue

 

I'll try to get something done in the next few days in order to provide a working example of using a composable for this. Hopefully this helps for now.

 

Happy Tweening!

Thanks again Rodrigo for your great answers.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...