300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > vue实现下拉框 模糊搜索+不区分大小写 (用到了el-select)

vue实现下拉框 模糊搜索+不区分大小写 (用到了el-select)

时间:2021-07-14 05:54:32

相关推荐

vue实现下拉框 模糊搜索+不区分大小写 (用到了el-select)

效果图

<el-form-item label="国家" prop="country"><el-select v-model="dataForm.country" style="width:300px"filterableremotereserve-keywordplaceholder="请输入关键词":remote-method="remoteMethod" clearable><el-option v-for="(item,index) in countryOpt" :key="index" :value="item.value" :label="item.label"></el-option></el-select></el-form-item>

data(){return{countryList:[],//所有国家 我的数据是后端返回的countryOpt:[],//展示的国家dataForm:{country:'',},}},

实现模糊查询的方法

remoteMethod(query){if(query != ''){this.countryOpt = []for(let i in this.countryList){// 模糊查询且不区分大小写if((this.countryList[i]).toLowerCase().indexOf(query.toLowerCase()) != -1){ //未匹配成功时返回-1let obj = {value:this.countryList[i],label:this.countryList[i],}this.countryOpt.push(obj)}}}else{for(let i in this.countryList){let obj = {value:this.countryList[i],label:this.countryList[i],}this.countryOpt.push(obj)}}},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。