el-input模糊查询
时间: 2023-11-06 11:55:16 浏览: 118
el-input模糊查询可以使用el-autocomplete或el-select和el-option两种方式来实现。具体实现的思路方式需要与后端进行商量确定。在前端,你需要为输入框添加@input事件,并通过v-model绑定数据。当输入内容时,触发@input中的事件search。在search方法中,你可以使用循环遍历匹配输入内容和列表中的数据,如果匹配成功,则将匹配结果存放在showList数组中。下面是一个完整的示例代码:
<template>
<div>
<el-input v-model="inputData" @input="search()"></el-input>
<p v-for="value in showList" :key="value">{{value}}</p>
</div>
</template>
<script>
import Vue from 'vue'
export default {
data() {
return {
inputData: "", //输入的数据
list: ['a', 'ab', 'abc', 'abcd', 'abcdef', 'abcdefg', 'abcdefgh'], //用于匹配的数据
showList: [] //存放匹配的结果
};
},
methods: {
search() {
this.showList = []; //先清空,存放当前搜索的匹配结果
for (let value of this.list) { // 在list中寻找与输入内容inputData匹配的内容
if (value.indexOf(this.inputData) !== -1) { //若匹配则存到对应的数组中
Vue.set(this.showList, this.showList.length, value);
}
}
}
}
};
</script>
<style scoped>
</style>
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)