I have a small web application written in Vue.js and I am trying to show a loading indicator on the page while a list of items is being filtered and re-rendered. The list is not fetched asynchronously, it is just a list of items from a computed property, based on some filter fields and is updated as the filters are changed. There is a delay of a few seconds before the list is updated in the UI because the list has about 1400 items and each item is a card-style component with an image, a button, icons, and some text. I have attempted to show a "Loading..." message between filter changes and new list rendering, but can't seem to get it to show to the user.
I have put together a simplified fiddle as an example: https://jsfiddle.net/zm4z9657/1/
EDIT: Here is the code snippet:
new Vue({ el: '#app', data: { even: false, loading: false }, computed: { numbers: function() { this.rerender(); return this.even ? _.range(0,100000,2) : _.range(0,100000); } }, methods: { rerender: function() { var self = this; /* self.loading = true */; //this.$nextTick(() => { self.loading = true; console.log('re-render start') this.$nextTick(() => { self.loading = false; console.log('re-render end') }) //}) }, } }) <script src="https://unpkg.com/vue"></script> <script src="https://unpkg.com/lodash"></script> <div id="app"> <input type="checkbox" value="1" v-model="even" /> even? <div v-if="loading" id="loading"> Loading... </div> <div v-else id="loaded"> <div> <div v-for="number in numbers" :key="number">{{number}}</div> </div> </div> </div> The sample shows a list of numbers 1-100000, and when you click the "even ?" checkbox filter, it causes the list to update with only even numbers. 100000 was used to show the slight delay in the rendering of the new list. If you inspect the DOM, you can see that after checking/unchecking the checkbox, the <div id="loading"> pops into the DOM for a short bit, then changes over to the new list inside <div id="loaded">. Although the loading <div> is shown in the DOM, it is never updated in the UI.
I have code I hoped would show "loading" when the computed property is called, and when the list is done rendering, hide it and show the list. Why is this not working? Why does the DOM change, but the UI is never updated? Is the UI not updating because all the dynamic elements are in the same component and it is not flushed until the list is done rendering? Is there a better way to achieve this?
Thanks!
v-showto hide the display with the data being filtered, and show the loading image<>button in the editor