如何使用dropzone&上传文件vueJs

时间:2016-05-18 09:05:26

标签: javascript laravel-5 dropzone.js vue.js

请帮助我..
我正在使用DropzoneJs& vueJs,我想使用dropzone.js在vueJs中上传文件但是不起作用,我试过这样的& msg错误

uploadImageGallery.options.autoProcessQueue = true is not a function
uploadImageGallery.processQueue is not a function

我怎么能解决这个问题..?

function uploadImageGallery()
{
    Dropzone.autoDiscover = false;
    var uploadImageGalleryVar = $(".upload__button__news").dropzone({ 
        url: base_url+"/myRoute",
        addRemoveLinks: true,
        dictCancelUpload: "",
        autoProcessQueue: false,
        dictRemoveFile: "x"
    });
}

var vmGallery = new Vue({
    el: '#GalleryController',
    data: { },
    methods: {     
        AddGallery: function () {
            console.log('add');
           uploadImageGalleryVar.options.autoProcessQueue = true;
           uploadImageGalleryVar.processQueue();
        },
    },

    ready: function () { 
          uploadImageGallery();
    }

});

1 个答案:

答案 0 :(得分:0)

  • 将该功能移至您的方法中,以便您可以通过this
  • 访问vm
  • 使用new Dropzone()创建Dropzone实例,而不是$().dropzone?
  • 将新实例另存为vm属性而不是变量
  • 通过该属性以其他方式访问它

像这样:

var vmGallery = new Vue({

  el: '#GalleryController',
  data: {},

  methods: {
      AddGallery() {
        console.log('add');
        // access dropzone instance through vm property
        this.uploadImageGalleryVar.options.autoProcessQueue = true;
        this.uploadImageGalleryVar.processQueue();
      },

      // move function into yor methods.
      uploadImageGallery() {
        Dropzone.autoDiscover = false;
        // save dropzone instance as vm property
        // use new Dropzone() to create it instead of jQuery shortcut
        this.uploadImageGalleryVar = new Dropzone($(".upload__button__news"), {
          url: base_url + "/myRoute",
          addRemoveLinks: true,
          dictCancelUpload: "",
          autoProcessQueue: false,
          dictRemoveFile: "x"
        });
      }
  },

  ready: function() {
    uploadImageGallery();
  }
});

就是这样