过滤器是根据过滤条件,留下符合条件的
totalData() {
// this.tableData是后端返回的一个对象数组
const tableData = this.tableData;
// searchKey是搜索框输入的关键字
const searchKey = this.searchKey.toLowerCase().trim()
return tableData.filter((item) => {
//搜索框为空,则返回全部数据
if (!searchKey) {
return true
}
//如果搜索框的值和对象中的某个key相匹配,则返回符合条件的对象数组
return item.state === searchKey || item.namespace === searchKey || item.name === searchKey
})
},