Vue 2 Dropzone Component

3.6.0 · maintenance · verified Sun Apr 19

Vue2-dropzone is a Vue 2 wrapper component for the popular Dropzone.js library, enabling easy integration of drag-and-drop file upload functionalities into Vue applications. The current stable version is 3.6.0. While the project is functional and receives periodic maintenance updates for bug fixes, dependency upgrades (such as Dropzone.js itself), and minor feature enhancements like support for new image formats, it is actively seeking co-maintainers, indicating a shift towards community-driven maintenance. Its primary differentiator is providing a pre-packaged Vue 2 component for Dropzone.js, abstracting away direct DOM manipulation. A separate, Nuxt SSR-compatible version is also available from a different maintainer. Releases are typically driven by bug reports, security patches, and updates to the underlying Dropzone.js library.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `vue2-dropzone` into a Vue 2 component, configuring various upload options such as URL, file size, accepted types, and custom headers, while also handling success and error events during file uploads. It includes the necessary CSS import and shows how to use the component in a template.

import { defineComponent } from 'vue';
import VueDropzone from 'vue2-dropzone';
import 'vue2-dropzone/dist/vue2Dropzone.min.css';

export default defineComponent({
  name: 'FileUploadComponent',
  components: {
    VueDropzone
  },
  data() {
    return {
      dropzoneOptions: {
        url: 'https://httpbin.org/post', // Replace with your actual upload endpoint
        thumbnailWidth: 150, // px
        maxFilesize: 2, // MB
        acceptedFiles: '.jpeg,.jpg,.png,.gif,.webp', // Supported file types
        addRemoveLinks: true,
        dictDefaultMessage: 'Drop files here or click to upload.',
        headers: {
          'X-CSRF-TOKEN': process.env.VUE_APP_CSRF_TOKEN ?? '', // Example for CSRF token
          'Custom-Header': 'MyValue'
        },
        // Optionally disable auto-processing and manually trigger uploads
        // autoProcessQueue: false,
      }
    };
  },
  methods: {
    dropzoneSuccess(file, response) {
      console.log('File uploaded successfully!', file, response);
      // Access component instance to interact with Dropzone.js methods
      // (this.$refs.myVueDropzone as any).removeFile(file);
    },
    dropzoneError(file, message, xhr) {
      console.error('Error uploading file:', file, message, xhr);
    },
    dropzoneRemovedFile(file, error, xhr) {
      console.log('File removed from queue:', file);
    },
    // Example of a manual upload trigger
    // processQueue() {
    //   (this.$refs.myVueDropzone as any).processQueue();
    // }
  }
});

view raw JSON →