I have a reference variable called foxArticles
that holds a list containing 100 items. Using a v-for loop, I iterate over each value and render all 100 values on the page.
<template>
<div class="news_container">
<div
v-for="article in foxArticles"
v-bind:key="article"
class="article_single_cell"
>
<div
class="news_box shadow hover:bg-red-100"
v-if="containsKeyword(article, keywordInput)"
>
<div class="news_box_right">
<div class="news_headline text-red-500">
<a :href="article.url" target="_blank">
{{ article.title }}
</a>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
const foxArticles = ref([]);
</script>
Additionally, there is a search function in place that checks if an article includes the entered keyword. This function is utilized within the v-for loop.
<div class="search_input_container">
<input
type="text"
class="search_input"
v-model="keywordInput"
/>
</div>
<script>
const keywordInput = ref("");
function containsKeyword(article, keywordInput) {
if (article.title.toLowerCase().includes(keywordInput.toLowerCase())) {
return article;
}
}
</script>
The challenge arises when attempting to use .slice() on the foxArticles
array within the v-for loop, causing issues with the search functionality as it only returns values from the sliced range.
Is there a way to access all values of the array without rendering all 100 articles on the initial load? Any suggestions?