一、在表格标题处增加一个input用来根据关键字搜索库房 用v-model=“search”绑定输入
下面是
<el-table-column prop="warehouseName" label="库房" :show-overflow-tooltip="true" header-align="left" align="left"> <template slot-scope="scope"> {{scope.row.warehouseName}} </template> <template slot="header" slot-scope="scope"> <el-row :span="24"> <el-col :span="6" class="custom-title" style="padding-top: 5px;color:rgb(12, 123, 164); font-size:12px;line-height: 2;">库房</el-col> <el-col :span="18" class="search-before-content"> <el-input v-model="search" size="mini" placeholder="输入关键字搜索" /> </el-col> </el-row> <hr class="hr-custom-style" /> </template> </el-table-column>二、在js文件中处理
data: function data() { return { cameraTableData: [], search:'' } }, computed: { // 模糊搜索 tables () { const search = this.search; if (search) { // filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。 // 注意: filter() 不会对空数组进行检测。 // 注意: filter() 不会改变原始数组。 return this.cameraTableData.filter(data => { // some() 方法用于检测数组中的元素是否满足指定条件; // some() 方法会依次执行数组的每个元素: // 如果有一个元素满足条件,则表达式返回true , 剩余的元素不会再执行检测; // 如果没有满足条件的元素,则返回false。 // 注意: some() 不会对空数组进行检测。 // 注意: some() 不会改变原始数组。 return Object.keys(data).some(key => { // indexOf() 返回某个指定的字符在某个字符串中首次出现的位置,如果没有找到就返回-1; // 该方法对大小写敏感!所以之前需要toLowerCase()方法将所有查询到内容变为小写。 return String(data[key]).toLowerCase().indexOf(search) > -1 }) }) } return this.cameraTableData } },