Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

Vue Draggable does not drop on canvas

I have a Laravel 11 , Breeze, Intertia 2 setup with Vue Draggable. Sidebar works with drag and drop, but I cannot drop onto the canvas

Here resources/js/Pages/Canvas.vue

And the sidebar resources/js/Pages/Sidebar.vue

and the builder resources/js/Pages/Builder.vue:

<template>
    <div class="builder">
      <Sidebar />
      <Canvas />
    </div>
  </template>
  
  <script setup>
  import Sidebar from './Sidebar.vue';
  import Canvas from './Canvas.vue';
  </script>
  
  <style scoped>
  .builder {
    display: flex;
  }
  </style>

I have resources/js/Components/ImageModule.vue and resources/js/Components/TextModule.vue with similar data (mainly dummy for now) so like

<template>
    <img :src="src" :alt="alt" class="image-module" />
  </template>
  
  <script setup>
  import { defineProps } from 'vue';
  
  const props = defineProps({
    src: {
      type: String,
      required: true,
    },
    alt: {
      type: String,
      default: '',
    },
  });
  </script>
  
  <style scoped>
  .image-module {
    width: 100%;
    height: auto;
  }
  </style>

Why can I not drop onto the Canvas?

0 likes
2 replies
LaryAI's avatar
Level 58

The issue you're experiencing with not being able to drop items onto the canvas could be due to several reasons. Let's go through a few potential solutions to ensure that the drag-and-drop functionality works as expected.

1. Ensure vuedraggable is properly imported and registered

Make sure that vuedraggable is correctly imported and registered in your components. It looks like you have done this correctly, but double-check to ensure there are no typos or import issues.

2. Check the group configuration

The group configuration in both the Sidebar.vue and Canvas.vue components should match. It looks like you have set this up correctly, but let's ensure that the pull and put options are correctly configured.

3. Ensure the modules array is reactive

Make sure that the modules array in Canvas.vue is reactive and properly updated when an item is dropped.

4. Verify the onDrop event handler

Ensure that the onDrop event handler is correctly defined and that it updates the modules array appropriately.

5. Check the CSS for the canvas

Ensure that the canvas has the correct CSS to allow items to be dropped onto it.

Updated Code Example

Here is an updated version of your Canvas.vue and Sidebar.vue components with some additional checks and improvements:

Canvas.vue

Sidebar.vue

Additional Debugging Steps

  1. Console Logs: Add console logs in the onDrop method to ensure that the event is being triggered and the item is being added to the modules array.
  2. Inspect Elements: Use browser developer tools to inspect the elements and ensure that the draggable items are being rendered correctly.
  3. Check Dependencies: Ensure that all dependencies (vuedraggable, vue, etc.) are up to date and compatible with each other.

By following these steps and ensuring that the configurations are correct, you should be able to resolve the issue and enable dropping items onto the canvas.

rhand's avatar
Level 6

Not working with that update. Did add minimum height for canvas to see if that helped:

But no change. Still cannot drop on canvas. I do have VueDraggable imported and added it in package.json:

{
    "private": true,
    "type": "module",
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "@inertiajs/vue3": "^1.0.0",
        "@tailwindcss/forms": "^0.5.3",
        "@vitejs/plugin-vue": "^5.0.0",
        "autoprefixer": "^10.4.12",
        "axios": "^1.7.4",
        "laravel-vite-plugin": "^1.0",
        "postcss": "^8.4.31",
        "tailwindcss": "^3.2.1",
        "vite": "^5.0",
        "vue": "^3.4.0"
    },
    "dependencies": {
        "vuedraggable": "^4.1.0"
    }
}

When I added console logging to Canvas.vue:

I had the failure error:

Drop event: DragEvent {isTrusted: true, _vts: 1725433568575, dataTransfer: DataTransfer, screenX: 515, screenY: 290, …}
Canvas.vue:32 Drop failed or no item added: DragEvent {isTrusted: true, _vts: 1725433568575, dataTransfer: DataTransfer, screenX: 515, screenY: 290, …}
onDrop @ Canvas.vue:32
callWithErrorHandling @ chunk-ZWD5XCL6.js?v=70d377c4:2501
callWithAsyncErrorHandling @ chunk-ZWD5XCL6.js?v=70d377c4:2508
invoker @ chunk-ZWD5XCL6.js?v=70d377c4:11371
Show 3 more frames
Show lessUnderstand this warning

So must be something else I am missing.

Please or to participate in this conversation.