如何使用dropzone&上传文件观点 [英] how upload file using dropzone & vueJs

查看:117
本文介绍了如何使用dropzone&上传文件观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我..
我正在使用DropzoneJs& vueJs,我想使用dropzone.js在vueJs中上传文件,但不起作用,我已经尝试过这样的&味精错误

hy help me please..
I'm Using DropzoneJs & vueJs, I want upload file in vueJs using dropzone.js but doesnt work, I have try like this & msg error

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();
    }

});

推荐答案

  • 将该函数移动到您的方法中,以便您可以通过this
  • 访问虚拟机
  • 使用new Dropzone()而不是$().dropzone?
  • 创建Dropzone实例
  • 将新实例另存为vm属性而不是变量
  • 通过该属性以其他方法访问它
    • move the function into your methods so you can access the vm via this
    • use new Dropzone() to create the Dropzone instance instead of $().dropzone?
    • save the new instance as a vm property instead of a variable
    • access it in other methods through that property
    • 赞:

      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();
        }
      });
      

      就这样

      这篇关于如何使用dropzone&上传文件观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆