0

I am new to vue.js and when I try to use this.$store.commit() inside a foreach loop I get this is undefined error:

items.forEach(function (obj, i) {
    obj.list.forEach(function (item) {
      this.$store.commit('completed'); 
      // gives error TypeError: this is undefined
    });
});

How can I make sure this works inside the loop?

Rain Man
  • 935
  • 1
  • 13
  • 42

0 Answers0