Reputation: 436
I m using Vue.js 3 and here I have search in data, but this data is from a fake API. So this search works only for small or big characters, but I want to search throw data no matter uppercase or lowercase? Here is my code
<template>
<div class='home'>
<h1>Third</h1>
<div v-if="error"> {{error}} </div>
<div v-if="posts.length">
<input type="text" v-model.trim="search" />
<!-- <p>search term - {{search}}</p> -->
<div v-for="post in matchingNames" :key='post.id'>
<h3>{{post.title }}</h3>
<h1>{{post.id}}</h1>
</div>
</div>
<div v-else> Loading...</div>
</div>
</template>
<script>
import { computed, ref, watch, watchEffect} from 'vue'
// import Listing from '../components/Listing.vue'
import getPosts from '../composables/getPosts'
export default {
name:'Third',
components: {} ,
setup(){
const search = ref('')
const{posts,error,load} = getPosts()
load()
const matchingNames = computed (()=> {
return posts.value.filter((post)=>post.title.match(search.value))
})
return {posts, error, search, matchingNames}
}
}
</script>
<style>
</style>
I also tried to replace match method with includes js method but the result is the same
This is a gif of how that now works, can anyone help me I'm new at Vue.js 3
Upvotes: 0
Views: 1339
Reputation: 7011
Convert both to lowercase first :)
...
return posts.value.filter((post)=>post.title.toLowerCase().includes(search.value.toLowerCase()))
...
Upvotes: 2