【发布时间】:2020-12-01 16:05:32
【问题描述】:
我正在尝试添加多个图像,但我找不到让它工作的方法。
我有这个方法:
imageAdd(e) {
e.forEach(function(e) {
if (e.type == 'image/jpeg' || e.type == 'image/png')
{
this.images.push({
image: URL.createObjectURL(e),
imageData: e
})
}
})
},
当我尝试推送到图像数组时,它给我带来了这个错误Cannot read property 'images' of undefined,尽管它是在我的数据中定义的。这里有什么问题?
【问题讨论】:
-
.forEach(/*...*/, this)或.forEach(/*...*/.bind(this)或相关。 -
@ASDFGerte 或箭头函数,我猜。
-
True,或者使用
for ... of而不是.forEach,这通常更胜一筹
标签: javascript vue.js