我有一个特殊的场景,我想从“this”访问数据,同时查看一个数组,该数组也在我的Vue组件上定义。例:
data () {
return {
question: [],
inputList: [],
form: {}
}
},
methods: {
onSubmit: function () {
let predictionParams = {}
this.inputList.forEach(function (element) {
predictionParams[element.detail] = this.form[element.detail]
})
}
错误:
this.form is not defined in the context of the forEach loop
问题:
JS处理此类案件的惯用方式是什么?我经常遇到这种情况,我总是觉得我想出了粗略的解决方案,或者至少可以做一些更容易的事情。对此的任何帮助都会很棒。
暮色呼如
炎炎设计
繁星点点滴滴
相关分类