vue.js - 从 dropzone.js 参数访问数据属性 - 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>
推荐阅读
- html - 在 p 标签中添加 ul 时,Angular 模板解析错误
- azure - 使用哪个 Azure 监控服务来可视化组件之间的关系?
- android - 根据过滤器将数组一分为二
- javascript - 如何在 Node.js 中声明和使用地图/字典?
- amazon-web-services - AWS Pinpoint:如何查看自定义指标
- dynamics-crm - Dynamics 365 本地 - Wep Api - 错误响应
- r - 将多项选择数据转换为数字
- c# - 这是我的连接字符串请告诉我有什么问题
- sql - 查询以获取给定表列的依赖视图定义和详细信息
- javascript - 如何使用 JQuery 的 else/if 语句更改图像 src?