검색 기능 : https://blog.csdn.net/bbs11007/article/details/110948483
이 검색 기능의 문구에 따르면 검색시 로컬 디버깅 트리에 문제가 있지만 패키지를 dist로 빌드 한 후 서버에 넣기 후 오류를 표시합니다. null의 'indexOf'속성을 읽을 수 없습니다.
let result = this.pages1.values.filter(row => {//this.pages1.values这个是表内所有数据
//搜索那列的内容,这里搜索name、id等列的内容
return row.name.indexOf(this.search1) > -1
|| row.id.indexOf(this.search1) > -1
|| row.code.indexOf(this.search1) > -1
|| row.note.indexOf(this.search1) > -1;
});
에러 메시지:
TypeError: Cannot read property 'indexOf' of null
at app.43208ea5.js:1
at Array.filter (<anonymous>)
at o.sousuo (app.43208ea5.js:1)
at click (app.43208ea5.js:1)
at it (chunk-vendors.ffbff91e.js:34)
at o.n (chunk-vendors.ffbff91e.js:34)
at it (chunk-vendors.ffbff91e.js:34)
at o.In.e.$emit (chunk-vendors.ffbff91e.js:34)
at o.handleClick (chunk-vendors.ffbff91e.js:1)
at it (chunk-vendors.ffbff91e.js:34)
즉, indexOf를 사용하면 판단시 오류 앞의 row.name이보고되며, 모두 비어 있는지 판단하기 위해 사용해야합니다.
if (row.name! = null || row.id! = null || ....) 너무 많은 문제입니다
메소드를 작성할 수 있습니다.
contains(prop, str) { //打包到服务器:
if (prop === null || prop === undefined) {
return false;
} else {
return prop.indexOf(str) > -1;
//如果需要大小写匹配
//return prop.indexOf(str.toUpperCase()) > -1;
}
},
그런 다음 아래 VUE의 문구를 수정하고 포함을 호출하여 추가하고 js 인 경우이를 제거하십시오.
let result = this.pages1.values.filter(row => {//this.pages1.values这个是表内所有数据
//搜索那列的内容,这里搜索name、id等列的内容
return this.contains(row.name, this.search1)
|| this.contains(row.id, this.search1)
|| this.contains(row.code, this.search1)
|| this.contains(row.note, this.search1)
});