Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
VueJS showing old data (images) before updating

For a shopping cart application with VueJS, I have a list of products paginated. All the products are fetched when the user opens the page and then I use a page variable to know which products to show. When I go from page 1 to page 2, the products are replaced by new ones but images take time to change. On my computer it takes like 1 second and on my phone 2 seconds. Some users tell me it's even longer. The problem is that while it's loading, it shows an image of another product from the previous page. So for some seconds on a new page, there are products with names and images not corresponding to them. Do you have any idea why this is happening ? If it takes time to load the new image, I prefer having nothing the time it loads instead of having an image of the previous page.

I have the same problem with the vutify v-autocomplete where each item has an image.

Overview of my pagination implementation (I don't think it's the problem because v-autocompetes has the same isssue):


<div
   v-for="(product, i) in productsByIDPaginated"
   :key="i"
   >
<img
   v-if="product.imagesNumber > 0"
   @click.stop="toProductDetailsPage(product)"
   :src="imageUrl(product)"
   @error="replaceByDefault"
   />
<img
   v-else
   @click="toProductDetailsPage(product)"
   src="../assets/unknown2.jpg"
   />
</div>
<script>
   productsByIDPaginated() {
         return this.productsByIDFiltred.slice(
           this.numberProdsByPage * (this.page - 1),
           this.numberProdsByPage * this.page
         );
       },
    
</script>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It would be helpful to see how the products and pagination are implemented.

I would assume that the old image does not change until after the new products are fetched. My best guess to solve this, assuming you are looping over the products, would be to make sure the keys are changed the moment new products are requested.

about 4 years ago · Juan Pablo Isaza Report

0

The reason of such behaviours (showing the old images on the next page (while pagination) until the new ones are loaded) is missing of :key="" prop, or passing to this prop the index of v-for (as you do).

You should:

  • pass an unique id of the iterated item if it has it (:key="item.id"), or
  • use :key="index + pageNum * itemsCountPerPage", or
  • as workaround, you can use an image URL as key prop.

So, for example, for the second case if you list 10 items per a page: on the first page items will have ID (key prop) from 0 to 9, on the next one — from 10 to 19.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!