我正在尝试从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
});
},
}
}
},
是否可以从函数内部访问它?
答案 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>