vue项目3秒内禁止按钮再次被点击

防止用户多次点击发布按钮

<el-button

            size="mini"

            icon="el-icon-collection"

            type="primary"

            class="m-l4"

            style="z-index: 9"

            @click="saveNote(2)"

            :disabled="abledBut"

            >暂存并发布</el-button>

         

扫描二维码关注公众号,回复: 16565015 查看本文章

data() {

    return {

      abledBut: false, //暂存并保存,true为禁止,false为不禁止

      time: 0,//设置初始时间为0

      timer: null,

      }

}

 //暂存并保存

    saveNote(saveType) {

      // console.log(this.ruleForm);

      let suid = document.getElementById("suid").value;

      let data = {

        SuId: suid,

        type: this.addType,

        publishType: saveType,

        articleId: this.checkItem.id,

        title: this.checkItem.title,

        titleSub: this.checkItem.titlesub,

        content: this.checkItem.content,

        filePath: this.checkItem.filepath,

        coverImg: this.checkItem.coverimg,

        userAllAccounts: this.ruleForm.userAllAccounts,

      };

      // console.log(data);

      this.$api.savaOrAdd(data).then((res) => {

        if (res.code == 0) {

          this.showNotice("保存成功!", false);

          this.getNoteList();

          return;

        }

        this.showNotice(res.msg || "保存失败!");

      });

      this.abledBut = true; // 设置为禁止

      this.time = 3;

      this.timer1();

      console.log("点击几秒禁用");

    },

    timer1() {

      //验证码60s内不能继续点击的函数

      if (this.time > 0) {

        this.time--;

        this.timer = setTimeout(this.timer1, 1000); 

      } else {

        this.time = 0;

        this.abledBut = false;

        clearTimeout(this.timer);

      }

    },

 本人是菜中菜,如果有误,欢迎指正!

猜你喜欢

转载自blog.csdn.net/m0_45218136/article/details/126241433