js防止按钮重复点击, 节流函数

252 阅读1分钟

提供两种方法

第一种使用 button的disabled属性

<el-button @click="gosearch" :disabled=state>搜索</el-button>
gosearch() {
        //disabled:true:禁用,false:可用
        let that = this
        if (that.seasts == false) {
          that.seasts = true
        }
        //根据条件改为false
        if ('接口调用返回成功') {
          that.seasts = false
        }
      },

第二种

<el-button @click="gosearch">搜索</el-button>
gosearch() {
        let that = this
        if (that.seasts == false) {
          that.seasts = true
        }else{
          that.$message.error('请勿重复点击')
          return false
        }
        //根据条件改为false
        if ('接口调用返回成功') {
          that.seasts = false
        }
      },