[Vuejs]-Vue cli axios mixing array indexes when getting requests

0πŸ‘

βœ…

I don’t know why but axios doing another loop selfly and mixing array indexes. For example;

for(i = 0; i<5; i++)
    {
      //your axios codes
       {
          //i = 0
          //i = 3
          //i = 2
          //i = 4
          //i = 1
       }
   //i = 0
   //i = 1
   //i = 2
   //i = 3
   //i = 4
    }

You should push your all datas to array in axios. Like ;

const sentenc = this.colocation[0][i].examples;
            sentenc.forEach((item,index) => {
            var colAction = this.colocation[0][i].examples[index];
            const strippedString = colAction.replace(/(<([^>]+)>)/gi, "");
              axios.get('https://www.googleapis.com/language/translate/v2?key={apikey}='+strippedString+'&source=en&target=tr')
                .then((response) =>{
                  const exTranslet = response.data.data.translations[0].translatedText;
                  this.examplesTR.push(exTranslet);
                  this.examplesEN.push(strippedString) //use this line in axios
                })
          })

Leave a comment