Vue renders only the first piece of data in the array

how can I take only the first piece of data in an array

Mar.14,2021

two ideas: one is that the traversal array length of data processing in advance is 1; Define list= [] in data; this.list.push (result.imgs [0]) in js; then change the v-for to "(img,index) in list";
the second way of thinking is to restrict the traversal code directly when traversing the line to
but when there is a large amount of data, the first performance is better


1.) No loop
2. Add result.imgs if = "index=0"


Direct result.imgs [0] after the loop


use slice to generate a new array, and then v-for New array:

<div class="list_img_holder_large" v-for="(img, index) in result.imgs.slice(0,1)">
    <img :src="">
</div>

ide/list.html-sharpv-for-with-v-if" rel=" nofollow noreferrer "> just read the document carefully and add v-if to judge

Menu