<script setup lang="ts">
import { onMounted, ref } from "vue";
defineOptions({
name: "HomeViewChild7",
});
let data1 = ref("data1-");
let data2 = ref("data2-");
async function fetchData1() {
return await new Promise((resolve) => {
setTimeout(() => resolve("模拟接口获取数据1"), Math.random() * 300);
});
}
async function fetchData2() {
let data = await new Promise((resolve) => {
setTimeout(() => resolve("模拟接口获取数据2"), Math.random() * 300);
});
return data;
}
async function promiseAll() {
const [Data1, Data2] = await Promise.all([fetchData1(), fetchData2()]);
console.log(Data1, Data2);
data1.value = data1.value + Data1;
data
promiseRace,promiseAll用法介绍
最新推荐文章于 2024-11-13 17:27:29 发布