微信小程序的搜索和重置功能
wxml
<template>
<div>
<div class="input-wrap">
<el-input
search
v-model="searchVal"
placeholder="请输入查询内容..."
@input="autosearch"
style="width: auto">
</el-input>
<el-button type="dashed" class="reset" @click="resetDate">重置</el-button>
</div>
<br />
<el-table border :data="showList">
<el-table-column prop="date" label="报名日期"></el-table-column>
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="studentId" label="学号"> </el-table-column>
<el-table-column prop="email" label="邮箱"> </el-table-column>
</el-table>
</div>
</template>
js
<script>
export default {
data() {
return {
searchVal: "",
showList: [],
newList: [],
dataList: [
{
date: "2019-09-26",
name: "刘邦",
studentId: 2016127206,
email: "839170766@qq.com"
},
{
date: "2018-09-26",
name: "韩信",
studentId: 2016127206,
email: "839170766@qq.com"
},
{
date: "2017-09-26",
name: "项羽",
studentId: 2016127206,
email: "839170766@qq.com"
},
{
date: "2015-09-26",
name: "周盖",
studentId: 2016127206,
email: "839170766@qq.com"
},
{
date: "2019-09-26",
name: "黄瑜",
studentId: 2016127207,
email: "839170766@qq.com"
},
{
date: "2019-09-26",
name: "刘邦",
studentId: 2016127208,
email: "839170766@qq.com"
},
{
date: "2019-09-26",
name: "项羽",
studentId: 2016127206,
email: "aaa@163.com"
},
{
date: "2019-09-26",
name: "刘邦",
studentId: 2016127206,
email: "xxx@189.com"
}
]
};
},
mounted() {
this.showList = this.dataList;
},
methods: {
autosearch() {
if (this.searchVal !== "") {
this.newList = this.dataList.filter(
item =>
item.email.indexOf(this.searchVal) !== -1 ||
item.date.indexOf(this.searchVal) !== -1 ||
item.name.indexOf(this.searchVal) !== -1 ||
item.studentId.toString().indexOf(this.searchVal) !== -1
);
if (this.newList) {
this.showList = this.newList;
}
}
},
resetDate() {
this.searchVal = "";
this.showList = this.dataList;
}
}
};
</script>