0👍
✅
This looks like a good use case for arrays and loops.
-
Instead of an object, put your sample text into an array, and iterate that with a
for
-loop. -
Update
scrambleText()
call to pass the array index instead of the object key previously used for your object:
const texts = reactive([ // 1️⃣
'インバウント',
'BtoB',
'セールス',
'OODA',
'指標',
//...
])
onMounted(() => {
for (let i = 0; i < texts.length; i++) { // 1️⃣
anime({
duration: 1000,
easing: 'linear',
loop: true,
update: scrambleText(texts[i], i), // 2️⃣
})
}
})
- In your template, use a
v-for
to iterate thetexts
array:
<ul>
<li v-for="text in texts">{{ text }}</li>
</ul>
0👍
You can put all your texts in an array and iterate over it like so:
<ul>
<li v-for="text in texts" :key="text">{{ text }}</li>
</ul>
Key given with the condition that all of your texts are unique.
And follow up with changing the functions in the onMounted
to do something like:
texts.forEach((text, index) => {
anime({
targets: ".main",
duration: 1000,
easing: "linear",
loop: true,
update: scrambleText(text, index),
});
});
Source:stackexchange.com