vue.js - 过滤接受小写或大写字符串的帖子列表

标签 vue.js quasar

我打算按标题过滤帖子列表。

逻辑已经实现并有效。

还有待解决的问题是无论字符串是否包含大写或小写字母都允许进行过滤。

例如:包含单词 Today 的字符串应该能够在输入中按小写字母过滤,即 today

inputFilter:function(){
      var vm = this;
      return vm.posts.filter((post) => {
           return post.title.match(searchValue);
      });
 }

如何解决?

最佳答案

您可以使用 toUpperCase() 或 toLowerCase() javascript 函数:)

无论您使用哪个函数,请务必将其应用于匹配语句的两边。否则,如果未转换的一面包含大写和小写字符的混合,它将无法匹配。

inputFilter:function() {
   var vm = this;
   return vm.posts.filter((post) => {
      return post.title.toUpperCase().match(searchValue.toUpperCase());
   });
}

inputFilter:function() {
   var vm = this;
   return vm.posts.filter((post) => {
      return post.title.toLowerCase().match(searchValue.toLowerCase());
   });
}

MDN Web Docs - String.prototype.toUpperCase()

MDN Web Docs - String.prototype.toLowerCase()

关于vue.js - 过滤接受小写或大写字符串的帖子列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60213857/

相关文章:

javascript - 在带有路由器 View 的 Vue3 中使用 async setup() 时出现空白

css - 运行 npx tailwindcss init -p 命令时找不到模块 'autoprefixer'

html - 是否有执行此布局的 2d for 循环?就像一条捷径

javascript - Laravel + VueJS : Prevent access to pages without permission

webpack-dev-server - 类星体 Assets 与静态目录

java - 在 Android 应用程序中使用 Quasar Fibers

typescript - Vue3 Typescript Prop 要么显示错误,要么根本不显示任何内容

vue.js - 重新加载 vue-tables-2 (Vuex) 的数据

android - 某些设备上不显示图像(使用 Quasar 框架)

vue.js - 多次下载卡住了我的应用-vuejs,类星体, Electron