const sentenc = this.colocation[0][i].examples;
sentenc.forEach((item,index) => {
var colAction = this.colocation[0][i].examples[index];
const strippedString = colAction.replace(/(<([^>]+)>)/gi, "");
this.examplesEN.push(strippedString)
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);
})
})我正在建立一个使用2个不同的apis的翻译器。当我将英文代置推送到数组时,不能将土耳其语代置推送到另一个相同索引号的数组。我怎么才能修复它?
发布于 2021-02-17 21:39:54
我不知道为什么,但是axios做了另一个循环selfly和混合数组索引。例如:
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
}您应该将所有数据推送到axios中的数组中。喜欢;
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
})
})https://stackoverflow.com/questions/66242864
复制相似问题