温馨提示:本文翻译自stackoverflow.com,查看原文请点击:vue.js - How do I lazy load item lists on Vuejs and Vuetify's lazyload?
vue.js vuejs2 vuetify.js

vue.js - 如何在Vuejs和Vuetify的lazyload上延迟加载项目列表?

发布于 2020-08-24 18:14:44

我想制作一个无限的滚动列表,但它实际上不是延迟加载,被困了几个小时,整个列表就会出现。

      .....
    <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:https : //jsonplaceholder.typicode.com/posts

查看更多

提问者
Pruthvi Shetty
被浏览
145
Zim 2020-05-07 22:38

我发现,列必须定义最小高度(约等于卡片的期望高度),以使v-lazy相交观察器正常工作。使用v-sheetv-responsive来设置min-height和包含卡片。

此外绑定v-modelv-lazy每一个岗位(即:post.isActive),而不是全局isActive无功...

        <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>

演示:https//codeply.com/p/eOZKk873AJ