3

In my app I am using Vuetify 2.0s v-data-table to display a table of data. I am trying to implement a loading linear-progress-bar while waiting for my elements to load. I am following the documentation , and when I add the props loading and loading-text="bla", it shows the loading text and linear-progress-bar, but after the elements load in the linear-progress-bar does not go away.

I have tried setting loading="elements", which then only shows the loading text and not the linear progress bar. I have also tried :loading="elements" which disables the entire loading feature.

<v-data-table
  :items="elements"
  :headers="elementsHeaders"
  :search="elementsSearch"
  hide-default-footer
  loading
  loading-text="Laden... even geduld aub"
>

I expect that with that code, when elements are loaded in that both the linear progress bar and loading text goes away.

3 Answers 3

12

You should use a boolean variable with the loading prop (add it to your component data).

data() {
   return {
      myloadingvariable: false
   }
}

Set it to true before starting loading data and to false when data have been loaded.

<v-data-table :loading="myloadingvariable" loading-text="Laden... even geduld aub">
Sign up to request clarification or add additional context in comments.

2 Comments

elements is a computed property, so I could set the loading variable to true before that, but then it returns this.elements, so not sure where to set it back to false.
How do you load data? Isn't it http request? Could you please share the code of the computed property?
4

Here is my solution

<v-data-table
  :items="elements"
  :headers="elementsHeaders"
  :search="elementsSearch"
  hide-default-footer
  :loading="loadTable"
  loading-text="Laden... even geduld aub"
>
data() {
   return {
    loadTable: true
   }
}

methods: {
  async listar() {
    const res = await axios.get('/especies');
    this.items = res.data;
    this.loadTable= false;
  },
}

Comments

1

I know it's an old topic, but I was searching for same thing just now.

Simply solved it using

:loading="!items.length"

2 Comments

That's ok, but you must be sure that your http request always returns at least one element
it doesnt work when you dont have any data in your list . actulayy when your list is empty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.