[Vuejs]-Make computations in a child component after axios requests in a parent component

0👍

You are getting the error because when the checkSpecifications method is run on mount, this.menuItems is not an array and forEach must only be used on arrays.

One option is to add a watcher to menuItems and only once it has been filled with a value (making sure it’s an array) then run the checkSpecifications method.

Alternatively, you could define menuItems as an array and provide a default value.

props: {
    menuItems: {
        type: Array,
        default: []
    }, 
    nutritionalValues: {
        type: Array,
        default: []
    }

It’s always good practice to define the type of your props.

Leave a comment