Array becomes Object in Vue

  • Hey,

    i have a question about a behavior that i don't understand.

    In my ModelTrait i have an method defined that delivers products grouped by product category. i did it like that:

    The type of the returning variable is an array.

    In the Controller that renders my page i called it like this:

    When i take a look at the vue dev tools, productsByCategory is an Object now. I really don't know why. Where is the trick to works with the original array?

    I hope somebody can help me...

  • Hm. I'm not a vue-expert. But just to test things: What happens if you do this in your controller:

  • Just use the following in your method.

    1. public static function getEnabledProductsByCategory() {
    2. // your code
    3. return array_values($result);
    4. }

    In your case you must reset the keys before, or else you'll get an object instead of an array when the json encoding happens.