本文主要是介绍Promise顺序打印#Vue3#for循环中调用接口顺序输出,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Promise顺序打印#Vue3#for循环中调用接口顺序输出
按照文件id来顺序打印出图片路径
<!-- <el-scrollbar max-height="500"> --><div v-for="(item, index) in testArr" style="float: left"><span>{{ index + 1 }}</span><img style="width: 30px; height: 30px; margin: 2px" :src="item" /></div><!-- </el-scrollbar> -->// 文件id
const demoArr = ref(["1800773345021661184","1800773345042632704","1800773305817501696","1800773305838473216","1800773261265604608","1800773261303353344","1800773211810566144","1800773211835731968","1800773211898646528","1800773992588644352","1800773992680919040","1800773896891404288","1800773931767042048","1800774035123081216","1800773852633108480","1800773810690068480","1800773810706845696","1800773724224491520","1800773724249657344","1800773671422398464","1800773434611994624","1800773386822094848","1800773387086336000","1800773387145056256","1799347203286896640",
]);// 下载文件
const getAxios = (val: any) => {return new Promise(function (resolve, reject) {DownFile({ id: val }).then((blob: any) => {const imageUrl = (window.URL || window.webkitURL).createObjectURL(blob);resolve(imageUrl);});});
};
let data1 = [];
let testArr = [] as any;
for (let i = 0; i < demoArr.value.length; i++) {let result = getAxios(demoArr.value[i]);data1.push(result);
}
Promise.all(data1).then((itemList: any) => {console.log("itemList", itemList);testArr = itemList.concat();console.log("testArr", testArr);
});
cccccc
这篇关于Promise顺序打印#Vue3#for循环中调用接口顺序输出的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!