Hey everyone,
I'm new to Nuxt coming from SvelteKit, I love the idea of auto-imports and love the work you are doing on Nuxt. One thing I'm struggling with here is how to make this code SSR friendly.
<script setup lang="ts">
interface Props {
text: string;
}
const props = defineProps<Props>();
const text = computed(() => {
const splitWord = props.text.split(' ').filter(Boolean);
const splitLetter = splitWord.map((word) => word.split('').map((letter) => ({ letter, shift: false })));
splitLetter.map((word) => {
const randomLetter = Math.round(Math.random() * (word.length - 1));
word[randomLetter].shift = true;
});
return splitLetter;
});
</script>
<template>
<template v-for="(word, index) in text">
<span>
<span v-for="letter in word" :class="{ 'font-heading': letter.shift }">
{{ letter.letter }}
</span>
</span>
<span v-if="index !== word.length - 1"> </span>
</template>
</template>
In our design we have one letter that has a different font, which letter in the world should be random each time. I've tried useState(() => Math.round(...)) but it will only key per file so it being in a each isn't right. Is the solution to break this down into smaller components? I'd prefer to not have the overhead.