How can I incorporate Vue draggable feature in my project using cards?

I've been attempting to integrate vuedraggable with Vuetify Cards, but I'm facing an issue where the drag and drop functionality doesn't seem to work when the cards are in a single row. Interestingly, it works perfectly fine when they are displayed in a column layout.

To see a working example, you can visit this CodeSandbox link.

In the Parent.vue file, if I remove the

<v-layout> </v-layout>
wrapping around the <HelloWorld /> component, the cards automatically switch to a column layout and the drag and drop feature starts functioning as expected.

This is the code snippet for my HelloWorld component:

<template>
  <v-flex xs4>
    <v-card class="mx-4">
      <v-img :src="src"></v-img>
      <v-card-title primary-title>
        <div>{{title}}</div>
      </v-card-title>
    </v-card>
  </v-flex>
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    title: String,
    src: String,
    id: Number
  },
  data() {
    return {};
  }
};
</script>

This is my Parent component implementation:

<template>
  <v-container>
    <v-layout class="mt-5 align-center justify-center row fill-height">
      <h2>Parent Component</h2>
    </v-layout>
    <draggable v-model="draggableCards">
      <v-layout>
        <template v-for="(tech,i) in getCardArray">
          <HelloWorld :src="tech.src" :title="tech.title" :key="i"/>
        </template>
      </v-layout>
    </draggable>
  </v-container>
</template>

<script>
import { mapGetters, mapMutations } from "vuex";
import HelloWorld from "./HelloWorld";
import draggable from "vuedraggable";
export default {
  components: {
    draggable,
    HelloWorld
  },
  computed: {
    ...mapGetters({
      getCardArray: "getCardArray"
    }),
    draggableCards: {
      get() {
        return this.$store.state.cardArray;
      },
      set(val) {
        this.$store.commit("setCardArray", val);
      }
    }
  },
  methods: {
    ...mapMutations({
      setCardArray: "setCardArray"
    })
  }
};
</script>

If anyone can provide assistance in resolving this issue, I would greatly appreciate it. Thank you.

Answer №1

To achieve a draggable container using v-layout, consider the following:

<draggable tag="v-layout" v-model="draggableCards">

For more details, you can refer to the code here

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

Breaking AngularJS into an array

I need help splitting my data stored in a single array into multiple arrays. Currently, I am using "|" as the separator to split them, but I want to store each split value in separate arrays. https://i.sstatic.net/wW5QV.png JavaScript: { $ ...

Experience a seamless front/back DIV transition with a mouseover effect similar to the ones on USAT

Recently, I was tasked with creating a mouseover transition effect for a div similar to the one used on USAToday's website. The structure of the boxes on the site includes: <div class="asset"> <div class="front">'image and some t ...

What is the best way to change the class of the inline table of contents element using JavaScript?

INQUIRY Hello, I am currently working on building a straightforward navigation site and I have a question regarding how to modify or add a class to one of the li elements within the inline table of contents (toc) on the right side. I want to style it usin ...

Troubleshooting CSS transition issues on ASP.NET Web Forms

Is there a way to make CSS3 transitions work in a .aspx page? I prefer Web Forms for designing forms and any suggestions would be helpful. The following is the code snippet from the .aspx page: <%@ Page Title="" Language="C#" MasterPageFile="~/Sit ...

Displaying conflicts in a single page by clicking on a checkbox

When I click on the <thead> checkbox of the first Table, it also checks the 2nd Table checkbox. However, that is not what I need. When I click on the First thead checkbox, all checkboxes in the first Table should be checked. Also, when I click on Fi ...

Learn how to efficiently pre-load data using the prefetchQuery method in React-Query

Attempting to pre-fetch data using react-query with prefetchQuery. The network tab in browser DevTools shows the requested data coming from the back-end, but strangely, the data is not present in the react-query DevTools cache. Any ideas on what might be c ...

Tips for sending Json data through a form to a controller and storing it in a database

I am working on a form that contains a sample table with values. The table (id=sampleTbl) has two columns: name and age. My goal is to save this data into my database table named person (id=AI, name, age) when the submitButton (id=idOfButton) is clicked. ...

Refreshing a page following an AJAX request made with jQuery

I am working on a JSP page that shows student details. When a student is selected from the dropdown box, it triggers an onchange event to retrieve the minimum and maximum marks for that student. <form name="listBean"> <c:forEach var="Item" i ...

Utilizing GCE API within my website

Currently, my goal is to retrieve GCE information in a read-only manner to showcase infrastructure data on my website. To achieve this, I aim to acquire an OAuth2 token using the JS API and then transmit it to a Python Backend for GCE API calls. It's ...

Creating custom routes with varying functionalities in express.js

I am currently facing a situation where I have multiple router.get functions in my code that I believe could be condensed into a single switch-case function. I have attempted the following approach: function handlerA(req, res) {} function handlerB(req, r ...

Creating a fluid side navigation bar in reactjs

Can someone please help me with the following code issue? I am encountering an error related to the script tag when running it in ReactJS, although it works fine in a simple HTML file. Upon starting npm, an error is displayed pointing to line number which ...

Utilizing Three.js with interactive functionalities and advanced transformation controls

I'm facing an issue with my project where I am using three.interaction to capture click events on certain objects and add transformControls to them. The problem I'm encountering is that the transform controls seem to block the click event on oth ...

When combining AJAX with PHP and HTML, one limitation to note is that PHP alone cannot generate or create the file

I am facing a particular problem here. Currently, I am using HTML with AJAX: <html> <head> <script> function ajax_post(){ // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to ...

Tips for Providing Real-Time Data for a Dynamic Chart in d3

I have a line chart sample from D3, and the issue I'm facing is that I need to continuously feed live data from a server at certain time intervals and use D3 to draw the chart based on this dynamic data. Despite my efforts to search for a solution, I ...

Value-based JavaScript object prototype

Is there a way to ensure that every new object I create has its own unique dataTransfer property? For instance, when I try something like Object.prototype.dataTransfer = new DataTransfer();, I want a.dataTransfer.prop to remain 1 even if b.dataTransfer.pro ...

Encountering an error when attempting to save an ajax JSON response to a variable and receiving an

I am attempting to make an ajax call and store the JSON response in a variable. My goal is to display the JSON response in two separate Jqgrids, with one displaying half of the response and the other displaying the remaining half. I need some ideas on how ...

Exploring the concept behind the Javascript ternary statement code snippet

Recently, I stumbled upon this code snippet and I'm trying to grasp its purpose. I do understand that it involves using a ternary operator to add an active class on menu click, but a more detailed explanation would be greatly appreciated. navClick: f ...

Using v-show in a Vue component of my own creation throws an TypeError: Unable to access property '_withTask' of undefined

I created a custom Vue component called "editable-image" as shown below: <template> <span style="position: relative; text-align: center; color: white; cursor: pointer; margin-right: 10px;" @mouseover="iconShown = true" @mouseleave="iconShown = ...

How can I turn off eslint validation in my Vue project?

I have a question about my configuration in vue.config.js. I've tried setting it as follows: module.exports = { lintOnSave: false } However, the changes don't seem to take effect. Can anyone provide guidance on how to disable eslint validati ...

Event handling in Node.js can sometimes result in throwing exceptions

I need advice on how to handle errors or return values from an event in my code. Here is what it looks like: _initConnection(){ try{ const errorValidation = this.errorValidation const HOST = "192.168.2.32" ...