Vue列表过滤+列表排序

const arr = 
this.persons.filter((p)=>{
    return p.name.indexOf(val) !== -1
})
不要修改原数据,
折叠 #region
     #endregion
当watch和computed都能实现的时候,优先使用computed
====================列表排序======================
sortType:0 //0原顺序 1降序 2升序
//判断一下是否需要排序
if(this.sortType){
    arr.sory((p1,p2)=>{
        return this.sortType === 1 ? p2.age-p1.age : p1.age-p2.age;
    })
    return arr;
}

猜你喜欢

转载自blog.csdn.net/a2285786446/article/details/127493815