Vue Axios顺序请求

<script lang="ts" setup>
import axios from "axios";

axios.defaults.baseURL = "http://127.0.0.1:8080";

let count: number = 0;

// 消息队列(存 Promise 链)
let queue = Promise.resolve();

const onClick = (cnt: number) => {
  queue = queue.then(() => doSomething(cnt));
}

const postRequest = async (cnt: number) => {
  await axios.post<string>("/get").then((value) => {
    console.log(cnt, value);
  });
}

const doSomething = async (cnt: number) => {
  console.log("do some preparation now...");
  await postRequest(cnt);
}

</script>

<template>
  <button @click="onClick(count++)">CLICK</button>
</template>

<style scoped>
</style>

There are no comment yet.

COMMENT

Take a Coffee Break

Recommend post

  1. 常用工具指令

    2022-09-18

ABOUT

Welcome to FullStar, a captivating online destination where the realms of software development and personal reflections intertwine.

September 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Life Logs

  1. 回首

    2023-07-14

Return Top