js --》 如何防止在請求接口時,禁止重復使用該接口?(重復提交問題)


<template>
  <div>

  </div>
</template>

<script>
import api from "@/components/api.vue";
import qs from "qs";
export default {
  data() {
    return {
      websockFlag: true,//開關變量
    };
  },
  methods: {
   //保存 saveItem() {
if (!websockFlag) { this.$message("正在請求中,請勿重復操作!"); this.websockFlag = true; return; } let parm = { token: JSON.parse(localStorage.userMsg).token, point_key: this.point_key, control_value: this.control_value }; this.websockFlag = false; // 解決異步,不要寫在api請求中 api.selectUserInfo(qs.stringify(param)).then(res => { if (res) { this.websockFlag = true; //清零 該次請求未完成,不允許進行下次請求 } if (res.code != 200) { this.$message({ message: "請求失敗!", type: "success", showClose: true }); } }); } } }; </script> <style lang="scss"> </style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM