I
I
Ilshat Gayanov2019-01-23 20:12:09
JavaScript
Ilshat Gayanov, 2019-01-23 20:12:09

Why is the loading animation not being removed?

When you click on the button, it produces an animation of loading simulation, but after the request is completed, the text inside the button becomes the original one, and the animation does not disappear, when you click it again, it is added, is it possible to solve this?
before:
5c48a03ae30db612456221.png
after:
5c48a042a7f4e841968360.png
Code:

<template>
      <b-button v-if="btnLoading"
                       variant="outline-warning"
                       class="d-block text-white text-uppercase"
                       disabled>
                       Подождите <i class="fas fa-spinner fa-spin"></i>
       </b-button>
       <b-button v-else="btnLoading" variant="outline-warning"
                        class="d-block text-white text-uppercase"
                        @click="buy()">
                        Купить за {{ product.original_price }} руб.
       </b-button>
</template>
<script>
        data() {
            return {
                tabIndex: 0,
                firstServer: {},
                product: {},

                order: {
                    nickname: '',
                    productId: ''
                },

                btnLoading: false
            }
        },
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-01-23
@ilshat_gayanov

<template>
  <b-button
    variant="outline-warning"
    class="d-block text-white text-uppercase"
    :disabled="btnLoading"
  >
    <span v-text="buttonText"></span>
    <i class="fas fa-spinner fa-spin" v-if="btnLoading"></i>
  </b-button>
</template>
<script>
...
    data() {
      return {
                tabIndex: 0,
                firstServer: {},
                product: {},

                order: {
                    nickname: '',
                    productId: ''
                },

                btnLoading: false
            }
        },
    
    computed: {
      buttonText() {
        return this.btnLoading
          ? 'Подождите'
          : `Купить за ${ this.product.original_price } руб.`;
      }
    }
...
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question