Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Vue draggable with cards?

I am trying to implement vuedraggable with Vuetify Cards but for some reason the drag and drop doesn't work when the cards are in a single row but works when they are in a column.

Check out this working CodeSandbox.

In the Parent.vue file, if i remove the <v-layout> </v-layout> wrapping the <HelloWorld /> component, the cards go into a column and the drag and drop starts working again.

This is 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:-

<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 someone can help me figure this out, i sure would appreciate it. Thank you.

like image 465
Somethingwhatever Avatar asked Mar 02 '23 11:03

Somethingwhatever


1 Answers

Try to use draggable container as v-layout, like a:

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

You can check code here

like image 89
strelok2010 Avatar answered Mar 05 '23 16:03

strelok2010