NuxtN
Nuxt12mo ago
jonspe

Calling Array.slice() to a fetched array says that slice is not a function

This is what's causing the problem, from what I've understood is that the array is wrapped in a proxy object. I've tried accessing the _rawValue and it worked for a while but it shouldn't be used.
<script setup>
const { data: posts } = useFetch("https://jsonplaceholder.typicode.com/posts")

const postsPerPage = 10
const currentPostIndex = ref(0)

const paginated = computed(() => posts.slice(currentPostIndex.value, currentPostIndex.value + postsPerPage))
... 

This is the error:
Uncaught (in promise) TypeError: posts.slice is not a function
    NuxtJS 6
index.vue:7:40
Was this page helpful?