https://github.com/xmflswood/pinyin-match
下面以vue-cli项目的代码做范例 1.先引用该工具,在用到的子组件单独使用
import PinyinMatch from 'pinyin-match'
2.使用computed即时过滤,注意,此方法使用与假分页
computed:{
liveCourseListPage(){
let that = this;
let filterList = []; //声明一个空的数组存放数据
$.each(that.liveCourseList, function (index, item) {
if(
(item.courseName && PinyinMatch.match(item.courseName,that.searchKeyword))
|| (item.teacherStr && PinyinMatch.match(item.teacherStr,that.searchKeyword))
){
filterList.push(item)
}
});
return filterList.slice((that.page.pageNo-1)*that.page.pageSize,(that.page.pageNo)*that.page.pageSize);
}
},