[Vuejs]-Unable to build array in component data after created event

1👍

Had a slight moment forgetting novice JavaScript principles

replacing:

vm.$set(vm.fixtures, m, element);

to:

vm.fixtures[m] = element;

did the trick.

0👍

To follow up on your own answer you can improve your code a little bit by doing the following:

setFixtureMonths: function (collection) {
        collection.forEach((element) => {

            let d = new Date(element.date);
            let m = d
                    .toLocaleString('default', {
                        month: 'long'
                    })
                    .toLocaleLowerCase();


            this.$set(vm.fixtures, m, element);

        });
    }

by replacing the anonymous function by an arrow function you will have access to the parent context, therefore no need to have let vm = this;

Leave a comment