Javascript 搜索不区分大小写

Javascript 搜索不区分大小写,javascript,vuejs2,Javascript,Vuejs2,我有一些代码它只搜索区分大小写的。我尝试了toUpperCase()/toLowerCase()方法 从“./json/data.json”导入json; 导出默认值{ 名称:“应用程序”, 数据(){ 返回{ 搜索:“”, blogs:json.slice(0,10), } }, 计算:{ filteredBlogs:函数(){ 返回this.blogs.filter((blog)=>{ 返回blog.title.match(this.search)|| blog.lineId.match(

我有一些代码它只搜索区分大小写的。我尝试了toUpperCase()/toLowerCase()方法


从“./json/data.json”导入json;
导出默认值{
名称:“应用程序”,
数据(){
返回{
搜索:“”,
blogs:json.slice(0,10),
}
},
计算:{
filteredBlogs:函数(){
返回this.blogs.filter((blog)=>{
返回blog.title.match(this.search)||
blog.lineId.match(this.search);
});
}
}
}

有人知道搜索不区分大小写吗?

假设
this.search
是一个字符串,当您将它传递给
match
时,默认情况下它是区分大小写的

尝试从此
显式创建正则表达式。使用提供大小写不敏感的
“i”
选项搜索

computed: {
  filteredBlogs: function(){
    return this.blogs.filter((blog)=>{

      const regex = new RegExp(this.search, 'i')

      return blog.title.match(regex) ||
        blog.lineId.match(regex);
    });
  }
}

嗨,欢迎来到这里。“所以”很高兴你成为社区的一员!你试过这么做吗?此外,请访问我们的网站,因为这将引导您从我们社区获得更多支持。
computed: {
  filteredBlogs: function(){
    return this.blogs.filter((blog)=>{

      const regex = new RegExp(this.search, 'i')

      return blog.title.match(regex) ||
        blog.lineId.match(regex);
    });
  }
}