简体   繁体   中英

how to fix typeError: cannot read properties of undefined (reading 'upload') in vue

I encountered this error in my program, what is the problem? (The files are correct).

:src="http://marketplus.io/${item.data.upload[0].link}"

 <div class="product-card"> <div class="product-card-top"> <NuxtLink:to="`/product/${item.id}`"> <img v-if="item.data" class="w-100":src="`http://marketplus.io/${item.data.upload[0].link}`" alt="product image" /> </NuxtLink> <div class="product-card-actions"> <button class="add-to-wishlist"> <i class="fas fa-heart"></i> </button> <button class="add-to-compare"> <i class="fas fa-random"></i> </button> </div> </div>

It looks like the item.data is not available at the first rendering, You should add a conditional rendering in your img element:

<img v-if="item.data" :src="http://marketplus.io/${item.data.upload[0].link}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM