"Maximize Interaction: Integrate interact.js with your Vue components

Previously, I had set up my project with two boards for dragging and dropping cards. However, I am now interested in experimenting with interact.js because it seems like a reliable library that is well-maintained. Since I am using vue for this project, I am unsure how to proceed.

I came across a blog post here that demonstrates the use of interact.js with swipeable cards, and I attempted to adapt it to my needs. Here is what my card component currently looks like:

<template>
  <v-card
    ripple
    class="primary"
    :id = "id"
    ref="interactElement"
  >
    <slot/>
  </v-card>
</template>

<script>
import interact from 'interactjs';

export default {
  props: ['id'],
  mounted() {
    const element = this.$refs.interactElement;
    console.log(element);
    interact(element).draggable({
      onstart: () => {
        console.log('---------start dragging');
      },
      onend: () => {
        console.log('---------end dragging');
      },
    });
  },
};
</script>

<style scoped>
  .v-card {
    height: 7rem;
    width: 7rem;
  }

  .draggable{
    touch-action: none;
    user-select: none;
  }
</style>

However, I am currently facing an issue where events like onstart are not triggering. Can anyone help me understand what I may be doing wrong?

I am also considering whether it would be better to follow this method or try using a wrapper for interact.js in vue like this one? I am unsure of the benefits of using such a wrapper, especially since I am relatively new to vue. Any insights would be appreciated.

Thank you in advance! :)

Answer №1

Interactjs is causing conflicts with event handlers inside v-card components.

<template>
  <div ref="interactElement">
    <v-card
      ripple
      class="primary"
      :id = "id"
    >
      <slot/>
    </v-card>
  </div>
</template>

Answer №2

An alternative Vue method that can be used instead of the on start method is Created(), which serves a similar purpose as the Mounted object.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When attempting to invoke the rest function, an error occurs stating that the dataService.init in Angular is not

Learning AngularJS has been my current focus. To practice, I have been working on a Quiz app tutorial. However, I encountered an issue when trying to call the rest function of a factory after injecting it into one of my controllers. The JSON data for this ...

When attempting to pass the `auth()->user()->name` from Laravel to a Vue template, an error occurs stating that it is not an object

Encountering an error when passing the auth()->user()->name to a vue template. Even after trying the meta method, the same error persists. It is confirmed that I am logged in to my system. Welcome.blade.php <script> window.user = @json( ...

Why is it necessary to type in localhost in the address bar when using node.js and socket.io instead of simply opening the client.html file directly?

I am intrigued by this topic. My suspicion is that it may be related to the temporary file created by socket.io, but I'm struggling to fully understand it... ...

JavaScript code to dynamically change the minimum value of an input field when the page

How can I use JavaScript to change the minimum value onload? I tried the following code but it didn't work: <script type="text/javascript">$(document).ready(function(){ $("#quantity_5c27c535d66fc").min('10'); });</script> ...

A guide on effectively utilizing nested arrays within a pcolumn prime ng data table

I have a nested array structure and I am utilizing PrimeNG data table to display the data. Below is the organization of my array: this.institutionalTimetable = [ {day: "Monday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'Eng ...

Encountering issues with CSS selectors when using Selenium WebDriver

I am encountering an error with the following code: elem = new Array() elem = driver.findElements(By.CssSelector('input')); What could be causing the issue in the code above? If I have an HTML form like this: <form role="form" method="post ...

Getting the value of elements with the same id in JavaScript can be achieved by utilizing the getElement

When I click on the first delete link, I want to display the value from the first input box. Similarly, when I click on the second delete link, I want to show the value from the second input box. Currently, it is always showing the value from the first del ...

Display a collection of objects using Jade / Pug syntax

Struggling to find resources on Pug / Jade templating, turning to this platform for help. I've been diving into documentation on iterations along with consulting this helpful link. Working with Node.js, Express, and pug for a school project - a mock ...

Tips for utilizing the onload function in jquery

Having an issue where I have a button that I want to set time, and in order for the function to run correctly, it needs to be defined on the body element. This works fine with plain JavaScript, but I am encountering an error when trying to use jQuery. < ...

Browsing a Collection of Objects within an Array in JavaScript

After making an ajax request to load a JSON file and parsing it to store a reference to the object, I encountered issues while trying to loop through the object due to its structure. Below is a snippet of the JSON data that I am working with: { "marker ...

Obtain the name of the object method from inside the method itself

Imagine having an object like this: var app = {} inside which there is a method: app = { initialize: function () { } } Is it possible to retrieve the name of the method 'initialize' from within the initialize() function without explicit ...

What is the best way to adjust an image's dimensions to fit a specific screen size without distorting it on a webpage?

Currently working on a website, and the top section has a small column on the right with an image taking up the majority of the space to the left. The problem arises when the image spills over the screen size, messing up the overall layout of the page. I d ...

Which method of loading website images is quicker: sequential or parallel, utilizing Javascript?

As I work on developing an AJAX image gallery that preloads multiple large images ranging from 120kB to 2MB before the lightbox appears, a question arises: should these images be loaded sequentially (waiting for one to preload at a time) or in parallel? Wh ...

Sending forms through the .NET platform

On my .NET page, I have implemented client-side validation for a submit button within the form element. var register = $('#<%= Register.ClientId %>'); register.click(function(){ validation.init(); return false; }); Disabling the f ...

Eliminating duplicate uploads in JavaScript

Within my HTML code, there is a section where users can drag and drop files for upload. Inside this area, there is also a "browse for files" button that triggers a hidden file input if users prefer the traditional upload method. Everything functions correc ...

After invoking call(), the object becomes 'this' on a worldwide scope

I have a list containing the names of different methods. var methodList = ['method1', 'method2', 'method3', 'method4']; I dynamically select a method based on certain criteria. These methods are part of a larger cl ...

Issue: Adjustment of elements' size using an "onclick" method when reaching specific screen width

Seeking assistance with implementing media queries in JavaScript. Can an object be resized from JavaScript code based on a specific screen width, rather than the default one? For example, if I have a button that opens a div with a height of 600px when cli ...

In TypeScript, both 'module' and 'define' are nowhere to be found

When I transpile my TypeScript using "-m umd" for a project that includes server, client, and shared code, I encounter an issue where the client-side code does not work in the browser. Strangely, no errors are displayed in the browser console, and breakpoi ...

Perform calculations exclusively on the chosen text using a checkbox

Hey, I'm looking to calculate the total from various selected input text forms that are chosen with a checkbox, as shown below: <input type="text" value="" name="moonrock"> <input type="checkbox" value="moonon" name="moon"> Any tips on h ...

An issue arises when trying to group and sum an array of objects due to difficulty converting strings to arrays in TypeScript

Below is the provided code snippet: Definition of Interface - interface IWEXInterface { readonly Date?: string; "Exec Qty"?: string; readonly Expiry?: string; } Data Collection - let data: IWEXInterface[] = [ { Date: &qu ...