'You may have an infinite update loop in a component render function in vue for iteration

I have an array with 4 objects, which I render as follows

<div v-for="item in cant_objetivos_tipo">
        {{ item.__data__.nombre_monitor_tipo + ' : ' + item.__data__.cantidad_objetivos }}
</div>

enter image description here

then when i try fill another array with the data as follows

<div v-for="item in cant_objetivos_tipo">
        {{ datapie.push(item.__data__.nombre_monitor_tipo + ' : ' + item.__data__.cantidad_objetivos) }}
</div

i get infinite loop error

datapie[] is declared before

<script>
    import axios from 'axios'
    
    export default {
        data() {
            return {
                cant_objetivos_tipo: [],
                datapie: [],
          }
        },...

I hope you can help me, thank you very much in advance



Solution 1:[1]

<template>
  <div v-for="(item,index) in cant_objetivos_tipo" :key="index">
        {{ item.__data__.nombre_monitor_tipo + ' : ' + item.__data__.cantidad_objetivos }}
  </div
</template>

<script>
import axios from 'axios';

export default
{
  name: 'MyCustomComponent',
  data() 
  {
    return {
      cant_objetivos_tipo: [],
    };
  },
  computed:
  {
    datapie()
    {
      return this.cant_objetivos_tip.map(item => item.__data__.nombre_monitor_tipo + ' : ' + item.__data__.cantidad_objetivos);
    }
  },
  created()
  {
    this.fetchData();
  }
  methods:
  {
    fetchData()
    {
      axios.get('/api/get_tipo_objectivos').then(response =>
      {
        this.cant_objetivos_tipo = response || [];
      });
    }
  }
}
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IVO GELOV