从dropzone.js参数访问数据属性-vuejs

时间:2019-02-06 20:48:45

标签: vue.js parameters dropzone.js

我正在尝试从dropzoneOption访问数据参数,如下所示:

data() {
  return {
    e1: 0,
    dropzoneOptions: {
      url: '/api/imageUpload',
      thumbnailWidth: null,
      thumbnailHeight: null,
      acceptedFiles: '.jpg, .jpeg, .png',
      autoProcessQueue: false,
      previewsContainer: '.preview-container',
      init: function() {
        this.on("addedfile", function(file) { 
          //Access to e1 params.
          //This.e1 not working
      });
      },
    }
  }
},

是否可以从函数内部访问它?

1 个答案:

答案 0 :(得分:2)

您是否尝试过这样写:

init: function () {
 const _this = this //assigning this as a variable
  this.on("addedfile", function(file) {
     console.log("Added file ", file); 
     console.log(_this.e1)
  });
}

您还可以加入一个dropzone事件:

    
[...]
fileAdded: {
    sendingEvent (file) {
      // access this.e1 here
    }
  }
<vue-dropzone v-on:vdropzone-file-added="fileAdded"></vue-dropzone>