[Vuejs]-Failing to fetch data when visiting page via link in Nuxt3

0👍

I think in your code main problem is the filter function. The t.id in trending does not work correctly.

I have refactored your code below like this & I think It working as you need

<script setup>
const { data: trips } = await useFetch(
  'https://jsonplaceholder.typicode.com/users'
);

const trending = [0, 1, 2, 3, 4];
const seasonalTrips = trips._rawValue.filter((t) => trending.includes(t.id));

// Use this way I think its better
const st = computed(() => {
  return trips.value.filter((t) => {
    return trending.includes(t.id);
  });
});
</script>

<template>
  <div>
    <pre>{{ seasonalTrips }}</pre>
    <pre>{{ st }}</pre>
  </div>
</template>


Here’s the Stackblitz Link

Leave a comment