#Best way to track how many of a component are currently visible.

3 messages · Page 1 of 1 (latest)

crystal sorrel
#

What would be the best way to keep track of how many of a given component are currently visible on a page?

#

Ideally such that each component could know if it's the first, second, third on a page, etc

crystal sorrel
#

I came up with this but it feels pretty hacky

<script setup>
  const app = useNuxtApp();
  const route = useRoute().path;
  if (app.route !== route) {
    app.route = route;
    app.sectionCount = 0;
  }
  app.sectionCount++;
</script>