When rendering a page with v-for, what do you do if one of the values you want to take may not exist key?

<li class="find-list-li" v-for="item in carSenseFindData" :key="item.index">
    <div class="img-box">
       <img :src="item.vehicleInOutPic[0]["platePic"] | transferPic" :onerror="defaultPeopleImg">
    </div>
</li>

for example, the platePic field to be fetched may not exist, and if the vehicleInOutPic array is empty, an error will be reported at that time, and it will not work either. Is there any convenient way to correct it? You still have to go through the data processed by carSenseFindData

.
Dec.23,2021

you add a ternary to determine whether the previous vehicleInOutPic is empty
your guarantee field can determine that your block is a value error


just the ternary operator

.
Menu