Warm tip: This article is reproduced from stackoverflow.com, please click
vue.js vuejs2 vuetify.js

How do I lazy load item lists on Vuejs and Vuetify's lazyload?

发布于 2020-07-28 14:27:34

Im trying to make an infinite scroll list but it's really not lazy loading, been stuck with this for hours, the whole list will come in.

      .....
    <v-col
      v-for="(post, i) in posts"
      :key="i"
      cols="12"
    >
    <v-lazy
    v-model="isActive"
    :options="{
      threshold: .5
    }"
    transition="fade-transition"
  >
          {{Content here}}
     </....

API used for test : https://jsonplaceholder.typicode.com/posts

Questioner
Pruthvi Shetty
Viewed
7
Zim 2020-05-07 22:38

I discovered that the columns need to have defined min-height (approx. to the expected height of the cards) in order for the v-lazy intersection observer to work. Use something like a v-sheet or v-responsive to set the min-height and contain the cards.

Also bind the v-model of the v-lazy to each post (ie: post.isActive), instead of a global isActive var...

        <v-col lg="3" md="4" sm="6" cols="12" v-for="(post, index) in posts">
                <v-sheet min-height="250" class="fill-height" color="transparent">
                    <v-lazy 
                        v-model="post.isActive" :options="{
                            threshold: .5
                        }"
                        class="fill-height">
                        <v-card class="fill-height" hover>
                            <v-card-text>
                                <v-row :key="index" @click="">
                                    <v-col sm="10" cols="12" class="text-sm-left text-center">
                                        #{{ (index+1) }}
                                        <h2 v-html="post.title"></h2>
                                        <div v-html="post.body"></div>
                                    </v-col>
                                </v-row>
                            </v-card-text>
                        </v-card>
                    </v-lazy>
                </v-sheet>
        </v-col>

Demo: https://codeply.com/p/eOZKk873AJ