Git Product home page Git Product logo

Comments (3)

oumoussa98 avatar oumoussa98 commented on July 19, 2024

I am unable to reproduce this, i've used it with server-rendered Nuxt 3 app and works just fine
If you manage to find a repro case, we would gladly reopen this issue.

from vue3-infinite-loading.

dosstx avatar dosstx commented on July 19, 2024

I am unable to reproduce this, i've used it with server-rendered Nuxt 3 app and works just fine If you manage to find a repro case, we would gladly reopen this issue.

Can you provide an example?

In my case, if you click the "disable JavaScript" setting in browser devtools, the data is not rendered to the client. How did you get this library to SSR in Nuxt3? I assume you need to move the code to the plugins folder and set it up there?

from vue3-infinite-loading.

dosstx avatar dosstx commented on July 19, 2024

Nevermind, I believe I got it working with SSR. Here's my example using Firebase Firestore. The key takeaway is to load a certain number of posts during script setup and then as the client is ready, the infinitePostHandler function is run during viewport scroll.

<template>
  <section>
    <article class="result" v-for="post in posts" :key="post.id">
      <h5>{{ post.title }}</h5>
      <p>{{ post.content }}</p>
    </article>
    <InfiniteLoading @infinite="infinitePostHandler">
      <template #spinner>
        <AppSpinner />
      </template>
      <template #complete>
        <span>There are no more posts</span>
      </template>
      <template #error="{ retry }">
        <button class="btn btn-outline-dark" @click="retry">
          Retry loading posts
        </button>
      </template>
    </InfiniteLoading>
  </section>
</template>

<script setup lang="ts">
import InfiniteLoading from 'v3-infinite-loading'
import 'v3-infinite-loading/lib/style.css'

interface Post {
  id: string
  title: string
  content: string
}

let posts = ref<Post[]>([])
let page = ref(1)

const { data } = await useFetch(`/api/posts/lazy/${page}`)
posts.value.push(...data.value)

const infinitePostHandler = async ($state: {
  complete: () => void
  loaded: () => void
  error: () => void
}) => {
  console.log('loading more...')

  try {
    // Load more posts
    page.value++
    const { data } = await useFetch(`/api/posts/lazy/${page.value}`)

    if (data.value && data.value.length < 10) {
      $state.complete()
    } else {
      posts.value.push(...data.value)
      $state.loaded()
    }
  } catch (error) {
    $state.error()
  }
}
</script>

from vue3-infinite-loading.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.