English 中文(简体)
为什么在有限的雕刻中我没有回头吗?
原标题:Why isn t my vue infinite scroll not returning profiles?

I ve got an firestore database and I m trying to use an infinite scroll on the profile page to load all the profiles but it isn t even getting the data from the database because I should be seeing the documents data appear in the console log. this is the javascript page which gets the documents and limits them to 8.

import { projectFirestore } from "../Firebase/Config";



const fetchPosts = async (lastPost) => {
    let query = projectFirestore.collection( Premium ).orderBy( createdAt ).limit(8)
    
    if (lastPost) {
      query = query.startAfter(lastPost.createdAt)
    }
  
    const snapshot = await query.get()
  
    const posts = snapshot.docs.map(doc => {
        console.log(doc.data())
      return { id: doc.id, ...doc.data() }
    })
  
    return posts
  }
  export default fetchPosts

这是诉讼一方

<script>
import { ref, reactive } from  vue 
import fetchPosts  from  ../../Composables/limitedProfiles 

export default {
  setup() {
    const state = reactive({
      posts: [],
      lastPost: null,
      fetching: false
    })

    const container = ref(null)

    const handleScroll = async () => {
      if (container.value.scrollTop + container.value.clientHeight >= container.value.scrollHeight && !state.fetching) {
        state.fetching = true

        const posts = await fetchPosts(state.lastPost)
        state.posts = [...state.posts, ...posts]

        if (posts.length) {
          state.lastPost = posts[posts.length - 1]
        }

        state.fetching = false
      }
    }

    return {
      container,
      handleScroll,
      ...state
    }
  }
}

</script>
<template>
    <br><br>
    <p class="text-5xl text-red-700 font-serif">Infinite scroll</p><br><br><br>
    <div ref="container" @scroll="handleScroll">
    <div v-for="post in posts" :key="post.id">
      
      <div class= "hover:scale-105 transition ease-in-out duration-300 bg-neutral-800 hover:bg-neutral-900 active:bg-neutral-900 text-neutral-400 font-bold rounded-xl">
  <br>
     <p>{{ post.Name }}</p>
     <img :src= "post.Pic1" class="object-contain ml-6 w-60 h-80 transition ease-in-out duration-300">
     <div class="grid grid-cols-2 grid-rows-fit text-left ml-6">
     <p>Location:</p>
     <p>{{ post.Location }}</p>
     <p>detail1:</p>
     <p>{{ post.detail1 }} /hr</p>
     <p>detail2:</p>
     <p>{{ post.detail2 }}</p>
     <p>detail3:</p>
     <p>{{ post.detail3 }}</p>
    </div>
  </div><br>
</div>
    <div v-if="fetching">Loading...
    </div>
    </div>
</template>

如果任何人能够看一看,让我知道我会做什么错事,我会感谢。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签