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

Access data attributes from dropzone.js parameters - vuejs

我正在尝试从 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
      });
      },
    }
  }
},

有没有办法从函数内部访问它?

你试过这样写吗:

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>