Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sbkl's avatar
Level 17

vue.js transition for loading data

Hello,

I would like to use vue transition to have an animated loading icon while data are loading.

Could you recommend a link that could help me to start? Or an example?

Thank you.

0 likes
5 replies
craigwebster's avatar
Level 3

Use font-awesome to get some spinning icons. Then have a Vue data variable called loading which you set to flase before the ajax request, and true after success. Show the spinner depending on the value of loading:

new Vue({
   data: {
    loading: false
    },
    ready: function() {
    this.loading = true;
      // GET request
      this.$http({url: '/someUrl', method: 'GET'}).then(function (response) {
          // success callback
    this.loading = false;
      }, function (response) {
          // error callback
      });
    }
})

Then in your html:

<i  v-show="loading" class="fa fa-spinner fa-spin"></i>
5 likes
sbkl's avatar
Level 17

That simple... Thanks @craigwebster

Was starting to work on manipulations with css rotate property. I guess it is using the same principle?

janokary's avatar

Very nice. @craigwebster you need to bind(this) in order to alter this.loading in the response function.

new Vue({
   data: {
    loading: false
    },
    ready: function() {
    this.loading = true;
      // GET request
      this.$http({url: '/someUrl', method: 'GET'}).then(
      function (response) {
          // success callback
          this.loading = false;
      }.bind(this),
      function (response) {
          // error callback
      });
    }
})
1 like
sbkl's avatar
Level 17

When I have too many results, the css animation is blocked.

I know my query can be improved but the purpose of this search icon is to notify the user the app is running.

Any idea?

Please or to participate in this conversation.