Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-如何在Vue.js中搜索大小写?_Javascript_Api_Vue.js_Search_Match - Fatal编程技术网

Javascript-如何在Vue.js中搜索大小写?

Javascript-如何在Vue.js中搜索大小写?,javascript,api,vue.js,search,match,Javascript,Api,Vue.js,Search,Match,我使用的是Vue.js 3,这里有搜索数据,但这些数据来自一个伪造的API。所以这个搜索只适用于小字符或大字符,但我想搜索抛出数据,不管大小写? 这是我的密码 <template> <div class='home'> <h1>Third</h1> <div v-if="error"> {{error}} </div> <div v-if="post

我使用的是Vue.js 3,这里有搜索数据,但这些数据来自一个伪造的API。所以这个搜索只适用于小字符或大字符,但我想搜索抛出数据,不管大小写? 这是我的密码

<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>

第三
{{error}}
{{post.title}}
{{post.id}
加载。。。
从“vue”导入{computed,ref,watchEffect}
//从“../components/Listing.vue”导入列表
从“../composables/getPosts”导入getPosts
导出默认值{
姓名:'第三',
组件:{},
安装程序(){
const search=ref(“”)
const{posts,error,load}=getPosts()
加载()
常量匹配名称=计算(()=>{
返回posts.value.filter((post)=>post.title.match(search.value))
})
返回{posts,error,search,matchingNames}
}
}
我还尝试用includesjs方法替换match方法,但结果是一样的

这是一个gif的工作原理,有人能帮我吗我是Vue.js 3的新手


先将两者转换为小写:)

。。。
返回posts.value.filter((post)=>post.title.toLowerCase().includes(search.value.toLowerCase())
...

非常感谢您!这很好用!我在过滤器和排序方面有一些问题,如果您有空的话,我可以在接下来的几天里问您一些关于这方面的问题吗?:)@我很高兴它能工作!对不起,我无法直接提供帮助。但是在这个网站上问更多的问题,如果我看到他们,我会很乐意帮忙的!:)这样,其他人也会从答案中受益!:)