【问题标题】:how upload file using dropzone & vueJs如何使用 dropzone 和 vueJs 上传文件
【发布时间】:2016-09-14 15:56:47
【问题描述】:

请帮帮我..
我正在使用 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();
    }

});

【问题讨论】:

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


    【解决方案1】:
    • 将函数移到你的方法中,这样你就可以通过this访问虚拟机
    • 使用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();
      }
    });
    

    就是这样

    【讨论】:

    • 感谢您的回答,但仍然对我有用,而且对于 msg 错误仍然相同“uploadImageGallery.options.autoProcessQueue = true 不是函数,uploadImageGallery.processQueue 不是函数”
    • 你能在 jsfiddle.net 上重现问题吗?
    • rivision msg 错误为“无法读取未定义的属性'选项'和未定义的 processQueue”
    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多