【问题标题】:disable button until response VUE禁用按钮直到响应 VUE
【发布时间】:2021-11-14 00:48:44
【问题描述】:

按钮:

<v-button
    class='btn'
    :isLoading='isLoading'
    @click.prevent='sendRequest'
  >
    Search
</v-button>

方法:

sendRequest() {
  this.formatError = false;
  this.$validator.validateAll().then(result => {
    if (result) {
      this.isLoading = true;
      request
        .get('/api/shop/search', { params: { q: this.queryString } })
        .then(res => {
          this.isLoading = false;
          if (res.data) {
            this.$emit('ReceivedResponse', res.data);
          }
        })
        .catch(() => (this.isLoading = false));
    }
  });
}

我们需要在按钮上挂起禁用,直到我们得到答案。 (防止多次请求)

我不知道如何挂起禁用。 在sendRequest() { 之后我需要this.BTN = disableTrue 之类的东西,当我得到答案时,在.then 中我需要更改this.BTN = disableFalse? 但是我怎样才能得到按钮来控制禁用呢?

【问题讨论】:

  • 以上代码有什么问题?这正是你想要的,还是有什么错误?
  • @ArmanGhaffarian 该按钮没有像我们希望的那样被阻止。只要点击几次,就会有很多响应来自服务器。因此,我想阻止直到答案

标签: vue.js vuejs2 axios


【解决方案1】:

试试

    <v-button
       class='btn'
       :disabled='isLoading'
       @click='sendRequest'
  >
    Search
</v-button>

【讨论】:

  • 大声笑,它的工作:D thx
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多