这里要讲清楚,搜索的是什么?页内搜索并不是ctrl+ f
这种搜索,它搜索的范围肯定是从后端拿到数据渲染在前端的数据,比如表格,列表等等。
这里以表格为例,要实现填入关键字,然后筛选出对应的表格,展示在页面上。
<el-input placeholder="搜索" v-model="value">
<el-button slot="append" type="primary" icon="h-icon-search" @click="doSearch(value)"></el-button>
</el-input>
data() {
value: ''
}
methods: {
doSearch(value) {
let a = [];
a.push(
...this.branchOffice.filter(item => item.branch.indexOf(value) > -1),...this.branchOffice.filter(item => item.delayNum == value)
)
this.branchOffice = a;
}
}
思路:
this.branchOffice.filter(item => item.branch.index(value)) //this.branchOffice为页面绑定的表格data
//再利用filter方法筛选,item.brach.indexOf(value)是用来判断branch是否含有value。
//a.push(...arra,...arrb) 这是用来拼接数组
//this.branchOffice = a 则用来渲染数据到页面