Jump to content
Search Community

Vue - Draggable Instance cannot be killed

zulfarrakk test
Moderator Tag

Recommended Posts

Hello,

 

I'm having an issue trying to destroy a Draggable instance on beforeDestroy and I always get the message that Draggable in not defined and so I can't kill the instance.

 

methods: {
      loadList(){

        setTimeout(() => {
          //gsap.registerPlugin(Draggable, InertiaPlugin);

          Draggable.create('#wrapper__drag', {
            type:'x',
            bounds: '.drag__inner-wrapper',
            autoScroll: 1,
            inertia: true
          });

        }, 1000);
      }
    },

mounted () {
      gsap.registerPlugin(Draggable, InertiaPlugin);

      this.$root.$on ('myEvent', () => {
        setTimeout(() => {
          this.loadList()
        }, 1500);
      });

},
    beforeDestroy() {
      Draggable.get('#wrapper__drag').kill();

}

 

In console I get: VM15175:1 Uncaught ReferenceError: Draggable is not defined

Please help me.

Link to comment
Share on other sites

I found out how to solve it:

 

data () {
      return {
        draggableItem: []
      }
    },

methods: {
      loadList(){

        setTimeout(() => {
          //gsap.registerPlugin(Draggable, InertiaPlugin);

          this.draggableItem = Draggable.create('#wrapper__drag', {
            type:'x',
            bounds: '.drag__inner-wrapper',
            autoScroll: 1,
            inertia: true
          });

        }, 1000);
      }
    },

mounted () {
      gsap.registerPlugin(Draggable, InertiaPlugin);

      this.$root.$on ('myEvent', () => {
        setTimeout(() => {
          this.loadList()
        }, 1500);
      });

},
    beforeDestroy() {
      this.draggableItem[0].kill();

}

 

Hope this can help someone

  • Like 2
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...