【问题标题】:How to react and deactivate only that button in Vuetify.js when the follow, unfollow button is clicked单击关注,取消关注按钮时,如何仅在 Vuetify.js 中反应和停用该按钮
【发布时间】:2021-05-31 17:31:36
【问题描述】:

我有一系列带有关注、取消关注状态的按钮,当我点击每个按钮时,我希望它的状态在一点延迟和停用后改变,并且按钮被重新激活,例如,如果按钮在关注模式,当被点击时,按钮将被停用并加载,直到执行了后端操作然后将其状态更改为取消关注。 但是现在只需单击一个按钮,所有按钮就会一起改变位置。

我的工作成果如下图:

我在用户端写的代码如下:

 <v-btn
   @click="join()"
   :loading="joinGroup"
   :disabled="joinGroup"
   dark
   v-show="joinBtn"
   color="#7256EA"
   class="mt-2 rounded-full bg-purple-gradient"
   >Join Group
 </v-btn>

我在后面写的代码如下:

<script>
data() {
    return {
      joinGroup: false,
 }
}

methods: {
      join: async function() {
      this.joinGroup = true;
      if (
        this.group.privacy == 1 ||
        (this.group.privacy == 2 && this.isFollower)
      ) {
        this.addGroupMember(true);
      } else if (this.group.privacy == 0) {
        await this.addGroupMember(false);
        this.sendJoinRequest();
        this.snackBarPrivate();
      } else if (this.group.privacy == 2 && !this.isFollower) {
        this.snackBarFollowers();
      }
      this.joinGroup = false;
    },
}
</script>

【问题讨论】:

  • 您的所有按钮都使用了:loading="joinGroup" 吗?

标签: javascript html vue.js nuxt.js vuetify.js


【解决方案1】:

我猜你的button 在v-for 中,每一行代表你的数据项。问题是你的每个按钮都绑定到你的joinGroup :loading 和:disabled,所以当你切换它true 时,它们都会显示状态。

但是,当您在 v-for 中时,您可以确定应该禁用/加载与您的项目相关的哪个按钮。我为您制作了一个代码笔,显示了Codepen 的概念。

您也可以使用 v-for 中的 index 来实现此目的,如下面的 sn-p 所示。

<div v-for="(item, index) in items">
         <v-btn 
           :disabled="disabled[index]" 
           :loading="loading[index]" 
           @click="letItLoad(index)">
             Test Button
         </v-btn>
</div>

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 2020-04-26
    • 1970-01-01
    • 2016-02-14
    • 2017-09-19
    相关资源
    最近更新 更多