Jump to content
Search Community

Using GSAP with VueJS 3 Composition API

hades test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi and welcome to the GreenSock forums.

 

Keep in mind that the setup method in the composition API runs before the component instance is created and it's purpose is to store the component's reactive data. In your particular case title is just a reference to a reactive data, nothing more. Is not a DOM node that GSAP can actually tween in the App. What you could do is create a reference that later in the component's lifecycle, can hold a GSAP instance, but it seems overkill IMHO.

 

The recommendation for using GSAP with Vue is to attach a GSAP instance to the component's instance in the mounted hook and use refs in the template to identify the DOM node you want to use, like this:

<template>
  <div ref="myElement" />
</template>

Then in the script tag:

import { gsap } from "gsap";

export default {
  mounted () {
    this.myTween = gsap.to(this.$refs.myElement, { /* GSAP Config Here */ });
  }
}

Keep in mind that the main purpose of the composition API is to avoid giant monolithic reactive setups in large applications, or smaller ones that need a scalable flexibility, but it shouldn't be a place to define your GSAP instances.

 

Happy Tweening!!!

  • Like 4
  • Thanks 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...