我打算按标题过滤帖子列表。
逻辑已经实现并有效。
还有待解决的问题是无论字符串是否包含大写或小写字母都允许进行过滤。
例如:包含单词 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());
});
}
关于vue.js - 过滤接受小写或大写字符串的帖子列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60213857/